Enhance tunnel key action parameters by adding destination UDP port. Signed-off-by: Hadar Hen Zion <had...@mellanox.com> Reviewed-by: Roi Dayan <r...@mellanox.com> --- man/man8/tc-tunnel_key.8 | 6 ++++++ tc/m_tunnel_key.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
diff --git a/man/man8/tc-tunnel_key.8 b/man/man8/tc-tunnel_key.8 index 17b15b9..2e56973 100644 --- a/man/man8/tc-tunnel_key.8 +++ b/man/man8/tc-tunnel_key.8 @@ -15,6 +15,7 @@ tunnel_key - Tunnel metadata manipulation .BR dst_ip .IR ADDRESS .BI id " KEY_ID" +.BI dst_port " UDP_PORT" .SH DESCRIPTION The @@ -61,6 +62,8 @@ Set tunnel metadata to be used by the IP tunnel device. Requires and .B dst_ip options. +.B dst_port +is optional. .RS .TP .B id @@ -71,6 +74,9 @@ Outer header source IP address (IPv4 or IPv6) .TP .B dst_ip Outer header destination IP address (IPv4 or IPv6) +.TP +.B dst_port +Outer header destination UDP port .RE .SH EXAMPLES The following example encapsulates incoming ICMP packets on eth0 into a vxlan diff --git a/tc/m_tunnel_key.c b/tc/m_tunnel_key.c index f4a20e2..58a3042 100644 --- a/tc/m_tunnel_key.c +++ b/tc/m_tunnel_key.c @@ -60,6 +60,20 @@ static int tunnel_key_parse_key_id(const char *str, int type, return ret; } +static int tunnel_key_parse_dst_port(char *str, int type, struct nlmsghdr *n) +{ + int ret; + __be16 dst_port; + + ret = get_be16(&dst_port, str, 10); + if (ret) + return -1; + + addattr16(n, MAX_MSG, type, dst_port); + + return 0; +} + static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n) { @@ -128,6 +142,14 @@ static int parse_tunnel_key(struct action_util *a, int *argc_p, char ***argv_p, return -1; } has_key_id = 1; + } else if (matches(*argv, "dst_port") == 0) { + NEXT_ARG(); + ret = tunnel_key_parse_dst_port(*argv, + TCA_TUNNEL_KEY_ENC_DST_PORT, n); + if (ret < 0) { + fprintf(stderr, "Illegal \"dst port\"\n"); + return -1; + } } else if (matches(*argv, "help") == 0) { usage(); } else { @@ -197,6 +219,14 @@ static void tunnel_key_print_key_id(FILE *f, const char *name, fprintf(f, "\n\t%s %d", name, rta_getattr_be32(attr)); } +static void tunnel_key_print_dst_port(FILE *f, char *name, + struct rtattr *attr) +{ + if (!attr) + return; + fprintf(f, "\n\t%s %d", name, rta_getattr_be16(attr)); +} + static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg) { struct rtattr *tb[TCA_TUNNEL_KEY_MAX + 1]; @@ -231,6 +261,8 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg) tb[TCA_TUNNEL_KEY_ENC_IPV6_DST]); tunnel_key_print_key_id(f, "key_id", tb[TCA_TUNNEL_KEY_ENC_KEY_ID]); + tunnel_key_print_dst_port(f, "dst_port", + tb[TCA_TUNNEL_KEY_ENC_DST_PORT]); break; } fprintf(f, " %s", action_n2a(parm->action)); -- 1.8.3.1