From 20d649d4bb017d5c8280205db545a274b15ae21c Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sat, 2 Jul 2016 12:46:04 +0200 Subject: [PATCH] geneve: add support to set flow label Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1339178 Upstream Status: iproute2.git commit 29bb2373a8777 Conflicts: - Missing formatting cleanup changes. - Added missing LABEL_MAX_MASK define. commit 29bb2373a8777d0c8b8c68450a872c19bc7f245c Author: Daniel Borkmann Date: Thu Mar 24 16:49:56 2016 +0100 geneve: add support to set flow label Follow-up for kernel commit 8eb3b99554b8 ("geneve: support setting IPv6 flow label") to allow setting the label for the device config. Signed-off-by: Daniel Borkmann --- ip/ip_common.h | 4 ++++ ip/iplink_geneve.c | 29 ++++++++++++++++++++++++----- man/man8/ip-link.8.in | 6 ++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/ip/ip_common.h b/ip/ip_common.h index 917fcf8..880890e 100644 --- a/ip/ip_common.h +++ b/ip/ip_common.h @@ -90,3 +90,7 @@ struct link_util *get_link_slave_kind(const char *slave_kind); #ifndef INFINITY_LIFE_TIME #define INFINITY_LIFE_TIME 0xFFFFFFFFU #endif + +#ifndef LABEL_MAX_MASK +#define LABEL_MAX_MASK 0xFFFFFU +#endif diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c index 13a6d80..fb0c6b1 100644 --- a/ip/iplink_geneve.c +++ b/ip/iplink_geneve.c @@ -18,14 +18,15 @@ static void print_explain(FILE *f) { fprintf(f, "Usage: ... geneve id VNI remote ADDR\n"); - fprintf(f, " [ ttl TTL ] [ tos TOS ]\n"); + fprintf(f, " [ ttl TTL ] [ tos TOS ] [ flowlabel LABEL ]\n"); fprintf(f, " [ dstport PORT ] [ [no]external ]\n"); fprintf(f, " [ [no]udpcsum ] [ [no]udp6zerocsumtx ] [ [no]udp6zerocsumrx ]\n"); fprintf(f, "\n"); - fprintf(f, "Where: VNI := 0-16777215\n"); - fprintf(f, " ADDR := IP_ADDRESS\n"); - fprintf(f, " TOS := { NUMBER | inherit }\n"); - fprintf(f, " TTL := { 1..255 | inherit }\n"); + fprintf(f, "Where: VNI := 0-16777215\n"); + fprintf(f, " ADDR := IP_ADDRESS\n"); + fprintf(f, " TOS := { NUMBER | inherit }\n"); + fprintf(f, " TTL := { 1..255 | inherit }\n"); + fprintf(f, " LABEL := 0-1048575\n"); } static void explain(void) @@ -40,6 +41,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, int vni_set = 0; __u32 daddr = 0; struct in6_addr daddr6 = IN6ADDR_ANY_INIT; + __u32 label = 0; __u8 ttl = 0; __u8 tos = 0; __u16 dstport = 0; @@ -90,6 +92,15 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, tos = uval; } else tos = 1; + } else if (!matches(*argv, "label") || + !matches(*argv, "flowlabel")) { + __u32 uval; + + NEXT_ARG(); + if (get_u32(&uval, *argv, 0) || + (uval & ~LABEL_MAX_MASK)) + invarg("invalid flowlabel", *argv); + label = htonl(uval); } else if (!matches(*argv, "dstport")) { NEXT_ARG(); if (get_u16(&dstport, *argv, 0)) @@ -150,6 +161,7 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, addattr_l(n, 1024, IFLA_GENEVE_REMOTE, &daddr, 4); if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0) addattr_l(n, 1024, IFLA_GENEVE_REMOTE6, &daddr6, sizeof(struct in6_addr)); + addattr32(n, 1024, IFLA_GENEVE_LABEL, label); addattr8(n, 1024, IFLA_GENEVE_TTL, ttl); addattr8(n, 1024, IFLA_GENEVE_TOS, tos); if (dstport) @@ -211,6 +223,13 @@ static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) fprintf(f, "tos %#x ", tos); } + if (tb[IFLA_GENEVE_LABEL]) { + __u32 label = rta_getattr_u32(tb[IFLA_GENEVE_LABEL]); + + if (label) + fprintf(f, "flowlabel %#x ", ntohl(label)); + } + if (tb[IFLA_GENEVE_PORT]) fprintf(f, "dstport %u ", ntohs(rta_getattr_u16(tb[IFLA_GENEVE_PORT]))); diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index 31a6190..3002e47 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -674,6 +674,8 @@ the following additional arguments are supported: .BI ttl " TTL " .R " ] [ " .BI tos " TOS " +.R " ] [ " +.BI flowlabel " FLOWLABEL " .R " ]" .in +8 @@ -693,6 +695,10 @@ the following additional arguments are supported: .BI tos " TOS" - specifies the TOS value to use in outgoing packets. +.sp +.BI flowlabel " FLOWLABEL" +- specifies the flow label to use in outgoing packets. + .in -8 .TP -- 1.8.3.1