tc: Optimize gact action lookup

When adding a filter with a gact action such as 'drop', tc first tries
to open a shared object with equivalent name (m_drop.so in this case)
before trying gact. Avoid this by matching the action name against those
handled by gact prior to calling get_action_kind().

Cc: Jiri Pirko <jiri@mellanox.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: David Ahern <dsahern@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
This commit is contained in:
Phil Sutter 2018-01-12 12:20:21 +01:00 committed by Stephen Hemminger
parent 9bed02a5d5
commit 6f7df6b2a1
3 changed files with 12 additions and 5 deletions

View File

@ -194,7 +194,10 @@ int parse_action(int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
} else { } else {
struct action_util *a = NULL; struct action_util *a = NULL;
strncpy(k, *argv, sizeof(k) - 1); if (!action_a2n(*argv, NULL, false))
strncpy(k, "gact", sizeof(k) - 1);
else
strncpy(k, *argv, sizeof(k) - 1);
eap = 0; eap = 0;
if (argc > 0) { if (argc > 0) {
a = get_action_kind(k); a = get_action_kind(k);

View File

@ -511,7 +511,7 @@ static const char *action_n2a(int action)
* *
* In error case, returns -1 and does not touch @result. Otherwise returns 0. * In error case, returns -1 and does not touch @result. Otherwise returns 0.
*/ */
static int action_a2n(char *arg, int *result, bool allow_num) int action_a2n(char *arg, int *result, bool allow_num)
{ {
int n; int n;
char dummy; char dummy;
@ -535,13 +535,15 @@ static int action_a2n(char *arg, int *result, bool allow_num)
for (iter = a2n; iter->a; iter++) { for (iter = a2n; iter->a; iter++) {
if (matches(arg, iter->a) != 0) if (matches(arg, iter->a) != 0)
continue; continue;
*result = iter->n; n = iter->n;
return 0; goto out_ok;
} }
if (!allow_num || sscanf(arg, "%d%c", &n, &dummy) != 1) if (!allow_num || sscanf(arg, "%d%c", &n, &dummy) != 1)
return -1; return -1;
*result = n; out_ok:
if (result)
*result = n;
return 0; return 0;
} }

View File

@ -132,4 +132,6 @@ int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt);
int cls_names_init(char *path); int cls_names_init(char *path);
void cls_names_uninit(void); void cls_names_uninit(void);
int action_a2n(char *arg, int *result, bool allow_num);
#endif #endif