aboutsummaryrefslogtreecommitdiffstats
path: root/tc/m_nat.c
diff options
context:
space:
mode:
Diffstat (limited to 'tc/m_nat.c')
-rw-r--r--tc/m_nat.c50
1 files changed, 13 insertions, 37 deletions
diff --git a/tc/m_nat.c b/tc/m_nat.c
index d502a819..31b68fb6 100644
--- a/tc/m_nat.c
+++ b/tc/m_nat.c
@@ -41,7 +41,7 @@ usage(void)
}
static int
-parse_nat_args(int *argc_p, char ***argv_p,struct tc_nat *sel)
+parse_nat_args(int *argc_p, char ***argv_p, struct tc_nat *sel)
{
int argc = *argc_p;
char **argv = *argv_p;
@@ -84,20 +84,18 @@ bad_val:
static int
parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n)
{
- struct tc_nat sel;
+ struct tc_nat sel = {};
int argc = *argc_p;
char **argv = *argv_p;
int ok = 0;
struct rtattr *tail;
- memset(&sel, 0, sizeof(sel));
-
while (argc > 0) {
if (matches(*argv, "nat") == 0) {
NEXT_ARG();
if (parse_nat_args(&argc, &argv, &sel)) {
- fprintf(stderr, "Illegal nat construct (%s) \n",
+ fprintf(stderr, "Illegal nat construct (%s)\n",
*argv);
explain();
return -1;
@@ -117,30 +115,7 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
return -1;
}
- if (argc) {
- if (matches(*argv, "reclassify") == 0) {
- sel.action = TC_ACT_RECLASSIFY;
- argc--;
- argv++;
- } else if (matches(*argv, "pipe") == 0) {
- sel.action = TC_ACT_PIPE;
- argc--;
- argv++;
- } else if (matches(*argv, "drop") == 0 ||
- matches(*argv, "shot") == 0) {
- sel.action = TC_ACT_SHOT;
- argc--;
- argv++;
- } else if (matches(*argv, "continue") == 0) {
- sel.action = TC_ACT_UNSPEC;
- argc--;
- argv++;
- } else if (matches(*argv, "pass") == 0) {
- sel.action = TC_ACT_OK;
- argc--;
- argv++;
- }
- }
+ parse_action_control_dflt(&argc, &argv, &sel.action, false, TC_ACT_OK);
if (argc) {
if (matches(*argv, "index") == 0) {
@@ -165,13 +140,13 @@ parse_nat(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct
}
static int
-print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
+print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
{
struct tc_nat *sel;
struct rtattr *tb[TCA_NAT_MAX + 1];
char buf1[256];
char buf2[256];
- SPRINT_BUF(buf3);
+
int len;
if (arg == NULL)
@@ -188,17 +163,18 @@ print_nat(struct action_util *au,FILE * f, struct rtattr *arg)
len = ffs(sel->mask);
len = len ? 33 - len : 0;
- fprintf(f, " nat %s %s/%d %s %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
- "egress" : "ingress",
- format_host(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
+ fprintf(f, " nat %s %s/%d %s", sel->flags & TCA_NAT_FLAG_EGRESS ?
+ "egress" : "ingress",
+ format_host_r(AF_INET, 4, &sel->old_addr, buf1, sizeof(buf1)),
len,
- format_host(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)),
- action_n2a(sel->action, buf3, sizeof (buf3)));
+ format_host_r(AF_INET, 4, &sel->new_addr, buf2, sizeof(buf2)));
+ print_action_control(f, " ", sel->action, "");
if (show_stats) {
if (tb[TCA_NAT_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_NAT_TM]);
- print_tm(f,tm);
+
+ print_tm(f, tm);
}
}