/* * m_defact.c simple example action module * * This program is free software; you can distribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Authors: J Hadi Salim (hadi@xxxxxxxxxx) * */ #include #include #include #include #include #include #include #include #include #include "utils.h" #include "tc_util.h" #include static void explain(void) { fprintf(stderr, "Usage: ... simp index [INDEX]\n"); fprintf(stderr, "Where: ACT_STRING := a simple string (not exceeding 16 chars" "INDEX := index value used\n"); } #define usage() return(-1) #ifndef ANAMSIZ #define ANAMSIZ 16 #endif int parse_simple(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) { int argc = *argc_p; char **argv = *argv_p; struct tc_defact *p; char k[ANAMSIZ]; struct rtattr *tail; if (argc < 2) return -1; p = malloc(sizeof(*p)); memset(p, 0, sizeof(*p)); memset (&k,0,ANAMSIZ); NEXT_ARG(); strncpy(k, *argv, sizeof(k)-1); argc--; argv++; if (argc && matches(*argv, "index") == 0) { NEXT_ARG(); if (get_u32(&p->index, *argv, 10)) { fprintf(stderr, "Illegal \"index\"\n"); return -1; } argc--; argv++; } p->action = TC_ACT_PIPE; tail = (struct rtattr *) (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)); addattr_l(n, MAX_MSG, tca_id, NULL, 0); addattr_l(n, MAX_MSG, TCA_DEF_PARMS, p, sizeof(*p)); addattr_l(n, MAX_MSG, TCA_DEF_DATA, k, strlen(k)+1); tail->rta_len = (((void *) n) + NLMSG_ALIGN(n->nlmsg_len)) - (void *) tail; *argc_p = argc; *argv_p = argv; return 0; } int print_simple(struct action_util *au,FILE * f, struct rtattr *arg) { SPRINT_BUF(b1); struct tc_defact *p = NULL; struct rtattr *tb[TCA_DEF_MAX + 1]; char *str; if (arg == NULL) return -1; memset(tb, 0, sizeof (tb)); parse_rtattr(tb, TCA_DEF_MAX, RTA_DATA(arg), RTA_PAYLOAD(arg)); if (tb[TCA_DEF_PARMS] == NULL) { fprintf(f, "[NULL simple parameters]"); return -1; } p = RTA_DATA(tb[TCA_DEF_PARMS]); fprintf(f, "simple action %s", action_n2a(p->action, b1, sizeof (b1))); fprintf(f, "\n\t index %d ref %d bind %d",p->index, p->refcnt, p->bindcnt); if (show_stats) { if (tb[TCA_DEF_TM]) { struct tcf_t *tm = RTA_DATA(tb[TCA_DEF_TM]); print_tm(f,tm); } } str = RTA_DATA(tb[TCA_DEF_DATA]); if (!strlen(str)) { fprintf(f, "\n\t EMPTY string!!!\n"); } else { fprintf(f, "\n\t DATA: <%s>\n",str); } fprintf(f, "\n "); return 0; } struct action_util simple_action_util = { .id = "simple", .parse_aopt = parse_simple, .print_aopt = print_simple, };