[PATCH iproute2-next v2 2/2] ip nexthop: support fdb destination port
From: Jack Ma <hidden>
Date: 2026-07-23 01:25:24
Subsystem:
the rest · Maintainer:
Linus Torvalds
The kernel gained NHA_DST_PORT, an optional per-nexthop UDP destination port for fdb nexthops. VXLAN uses it to reach several receivers that share an underlay IP but listen on different ports, load-balancing a flow across (IP, port) legs of one nexthop group. Wire it into `ip nexthop`: ip nexthop add id 1 via 192.0.2.1 fdb dst_port 4790 The port is parsed on add (sent as NHA_DST_PORT, __be16, network order) and printed back on dump/get. The kernel only accepts it together with fdb and a gateway. Signed-off-by: Jack Ma <redacted> --- ip/ipnexthop.c | 18 ++++++++++++++++-- ip/nh_common.h | 1 + man/man8/ip-nexthop.8 | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 14b525a..ad8ad0c 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c@@ -52,7 +52,7 @@ static void usage(void) "SELECTOR := [ id ID ] [ dev DEV ] [ vrf NAME ] [ master DEV ]\n" " [ groups ] [ fdb ]\n" "BUCKET_SELECTOR := SELECTOR | [ nhid ID ]\n" - "NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ]\n" + "NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ] [ dst_port PORT ]\n" " [ encap ENCAPTYPE ENCAPHDR ] |\n" " group GROUP [ fdb ] [ type TYPE [ TYPE_ARGS ] ] }\n" "GROUP := [ <id[,weight]>/<id[,weight]>/... ]\n"
@@ -531,6 +531,8 @@ static int ipnh_parse_nhmsg(FILE *fp, const struct nhmsg *nhm, int len, nhe->nh_blackhole = !!tb[NHA_BLACKHOLE]; nhe->nh_fdb = !!tb[NHA_FDB]; + if (tb[NHA_DST_PORT]) + nhe->nh_dst_port = rta_getattr_be16(tb[NHA_DST_PORT]); nhe->nh_family = nhm->nh_family; nhe->nh_protocol = nhm->nh_protocol;
@@ -593,7 +595,11 @@ static void __print_nexthop_entry(FILE *fp, const char *jsobj, print_rt_flags(fp, nhe->nh_flags); if (nhe->nh_fdb) - print_null(PRINT_ANY, "fdb", "fdb", NULL); + print_null(PRINT_ANY, "fdb", "fdb ", NULL); + + if (nhe->nh_dst_port) + print_uint(PRINT_ANY, "dst_port", "dst_port %u ", + nhe->nh_dst_port); if ((show_details > 0 || show_stats) && nhe->nh_hw_stats_supported) { open_json_object("hw_stats");
@@ -1112,6 +1118,14 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv) req.nhm.nh_family = AF_INET; } else if (!strcmp(*argv, "fdb")) { addattr_l(&req.n, sizeof(req), NHA_FDB, NULL, 0); + } else if (!strcmp(*argv, "dst_port")) { + __u16 port; + + NEXT_ARG(); + if (get_u16(&port, *argv, 0)) + invarg("\"dst_port\" value is invalid\n", *argv); + addattr16(&req.n, sizeof(req), NHA_DST_PORT, + htons(port)); } else if (!strcmp(*argv, "onlink")) { nh_flags |= RTNH_F_ONLINK; } else if (!strcmp(*argv, "group")) {
diff --git a/ip/nh_common.h b/ip/nh_common.h
index afbd16b..f58bad4 100644
--- a/ip/nh_common.h
+++ b/ip/nh_common.h@@ -33,6 +33,7 @@ struct nh_entry { bool nh_blackhole; bool nh_fdb; + __u16 nh_dst_port; bool nh_hw_stats_supported; bool nh_hw_stats_enabled;
diff --git a/man/man8/ip-nexthop.8 b/man/man8/ip-nexthop.8
index aad6869..f902c3c 100644
--- a/man/man8/ip-nexthop.8
+++ b/man/man8/ip-nexthop.8@@ -65,7 +65,9 @@ ip-nexthop \- nexthop object management .BR onlink " ] [ " .B encap .IR ENCAP " ] [ " -.BR fdb " ] | " +.BR fdb " ] [ " +.B dst_port +.IR PORT " ] | " .B group .IR GROUP " [ " .BR hw_stats " { "
@@ -210,6 +212,12 @@ A fdb nexthop group can only have fdb nexthops. Example: Used to represent a vxlan remote vtep ip. layer-2 vxlan fdb entry pointing to an ecmp nexthop group containing multiple remote vtep ips. +.TP +.BI dst_port " PORT" +UDP destination port to use for an fdb nexthop, in place of the VXLAN +device's default port. Only valid together with +.B fdb +and a gateway. .RE .TP
@@ -311,6 +319,11 @@ ip nexthop add id 5 via 192.168.1.2 fdb Adds a fdb nexthop with id 5. .RE .PP +ip nexthop add id 6 via 192.168.1.2 fdb dst_port 4790 +.RS 4 +Adds a fdb nexthop with id 6 forwarding to 192.168.1.2 on UDP port 4790. +.RE +.PP ip nexthop add id 7 group 5/6 fdb .RS 4 Adds a fdb nexthop group with id 7. A fdb nexthop group can only have
--
2.43.0