]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - tc/m_tunnel_key.c
rdma: Properly mark RDMAtool license
[mirror_iproute2.git] / tc / m_tunnel_key.c
index 5a0e3fc3c48fc1503957968d0a86b234daeb042f..9449287ea0b4fd77efaad7f6b6e788204f952208 100644 (file)
@@ -25,7 +25,7 @@ static void explain(void)
        fprintf(stderr, "       tunnel_key set <TUNNEL_KEY>\n");
        fprintf(stderr,
                "Where TUNNEL_KEY is a combination of:\n"
-               "id <TUNNELID> (mandatory)\n"
+               "id <TUNNELID>\n"
                "src_ip <IP> (mandatory)\n"
                "dst_ip <IP> (mandatory)\n"
                "dst_port <UDP_PORT>\n"
@@ -190,6 +190,22 @@ static int tunnel_key_parse_geneve_opts(char *str, struct nlmsghdr *n)
        return 0;
 }
 
+static int tunnel_key_parse_tos_ttl(char *str, int type, struct nlmsghdr *n)
+{
+       int ret;
+       __u8 val;
+
+       ret = get_u8(&val, str, 10);
+       if (ret)
+               ret = get_u8(&val, str, 16);
+       if (ret)
+               return -1;
+
+       addattr8(n, MAX_MSG, type, val);
+
+       return 0;
+}
+
 static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
                            int tca_id, struct nlmsghdr *n)
 {
@@ -201,7 +217,6 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
        int ret;
        int has_src_ip = 0;
        int has_dst_ip = 0;
-       int has_key_id = 0;
        int csum = 1;
 
        if (matches(*argv, "tunnel_key") != 0)
@@ -257,7 +272,6 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
                                fprintf(stderr, "Illegal \"id\"\n");
                                return -1;
                        }
-                       has_key_id = 1;
                } else if (matches(*argv, "dst_port") == 0) {
                        NEXT_ARG();
                        ret = tunnel_key_parse_dst_port(*argv,
@@ -273,6 +287,22 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
                                fprintf(stderr, "Illegal \"geneve_opts\"\n");
                                return -1;
                        }
+               } else if (matches(*argv, "tos") == 0) {
+                       NEXT_ARG();
+                       ret = tunnel_key_parse_tos_ttl(*argv,
+                                                       TCA_TUNNEL_KEY_ENC_TOS, n);
+                       if (ret < 0) {
+                               fprintf(stderr, "Illegal \"tos\"\n");
+                               return -1;
+                       }
+               } else if (matches(*argv, "ttl") == 0) {
+                       NEXT_ARG();
+                       ret = tunnel_key_parse_tos_ttl(*argv,
+                                                       TCA_TUNNEL_KEY_ENC_TTL, n);
+                       if (ret < 0) {
+                               fprintf(stderr, "Illegal \"ttl\"\n");
+                               return -1;
+                       }
                } else if (matches(*argv, "csum") == 0) {
                        csum = 1;
                } else if (matches(*argv, "nocsum") == 0) {
@@ -303,7 +333,7 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p,
        }
 
        if (action == TCA_TUNNEL_KEY_ACT_SET &&
-           (!has_src_ip || !has_dst_ip || !has_key_id)) {
+           (!has_src_ip || !has_dst_ip)) {
                fprintf(stderr, "set needs tunnel_key parameters\n");
                explain();
                return -1;
@@ -435,6 +465,23 @@ static void tunnel_key_print_key_opt(const char *name, struct rtattr *attr)
                                        tb[TCA_TUNNEL_KEY_ENC_OPTS_GENEVE]);
 }
 
+static void tunnel_key_print_tos_ttl(FILE *f, char *name,
+                                    struct rtattr *attr)
+{
+       if (!attr)
+               return;
+
+       if (matches(name, "tos") == 0 && rta_getattr_u8(attr) != 0) {
+               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_uint(PRINT_ANY, "tos", "\ttos 0x%x",
+                          rta_getattr_u8(attr));
+       } else if (matches(name, "ttl") == 0 && rta_getattr_u8(attr) != 0) {
+               print_string(PRINT_FP, NULL, "%s", _SL_);
+               print_uint(PRINT_ANY, "ttl", "\tttl %u",
+                          rta_getattr_u8(attr));
+       }
+}
+
 static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
 {
        struct rtattr *tb[TCA_TUNNEL_KEY_MAX + 1];
@@ -476,6 +523,10 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
                                         tb[TCA_TUNNEL_KEY_ENC_OPTS]);
                tunnel_key_print_flag(f, "nocsum", "csum",
                                      tb[TCA_TUNNEL_KEY_NO_CSUM]);
+               tunnel_key_print_tos_ttl(f, "tos",
+                                         tb[TCA_TUNNEL_KEY_ENC_TOS]);
+               tunnel_key_print_tos_ttl(f, "ttl",
+                                         tb[TCA_TUNNEL_KEY_ENC_TTL]);
                break;
        }
        print_action_control(f, " ", parm->action, "");