ip route: Add option to use nexthop objects
Add nhid option for routes to use nexthop objects by id. Example: $ ip nexthop add id 1 via 10.99.1.2 dev veth1 $ ip route add 10.100.1.0/24 nhid 1 $ ip route ls ... 10.100.1.0/24 nhid 1 via 10.99.1.2 dev veth1 Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
42cce67e71
commit
12387e2c14
14
ip/iproute.c
14
ip/iproute.c
|
|
@ -80,7 +80,7 @@ static void usage(void)
|
||||||
" [ table TABLE_ID ] [ proto RTPROTO ]\n"
|
" [ table TABLE_ID ] [ proto RTPROTO ]\n"
|
||||||
" [ scope SCOPE ] [ metric METRIC ]\n"
|
" [ scope SCOPE ] [ metric METRIC ]\n"
|
||||||
" [ ttl-propagate { enabled | disabled } ]\n"
|
" [ ttl-propagate { enabled | disabled } ]\n"
|
||||||
"INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ]...\n"
|
"INFO_SPEC := { NH | nhid ID } OPTIONS FLAGS [ nexthop NH ]...\n"
|
||||||
"NH := [ encap ENCAPTYPE ENCAPHDR ] [ via [ FAMILY ] ADDRESS ]\n"
|
"NH := [ encap ENCAPTYPE ENCAPHDR ] [ via [ FAMILY ] ADDRESS ]\n"
|
||||||
" [ dev STRING ] [ weight NUMBER ] NHFLAGS\n"
|
" [ dev STRING ] [ weight NUMBER ] NHFLAGS\n"
|
||||||
"FAMILY := [ inet | inet6 | mpls | bridge | link ]\n"
|
"FAMILY := [ inet | inet6 | mpls | bridge | link ]\n"
|
||||||
|
|
@ -809,6 +809,10 @@ int print_route(struct nlmsghdr *n, void *arg)
|
||||||
print_string(PRINT_ANY, "src", "from %s ", b1);
|
print_string(PRINT_ANY, "src", "from %s ", b1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tb[RTA_NH_ID])
|
||||||
|
print_uint(PRINT_ANY, "nhid", "nhid %u ",
|
||||||
|
rta_getattr_u32(tb[RTA_NH_ID]));
|
||||||
|
|
||||||
if (tb[RTA_NEWDST])
|
if (tb[RTA_NEWDST])
|
||||||
print_rta_newdst(fp, r, tb[RTA_NEWDST]);
|
print_rta_newdst(fp, r, tb[RTA_NEWDST]);
|
||||||
|
|
||||||
|
|
@ -1080,6 +1084,7 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||||
int table_ok = 0;
|
int table_ok = 0;
|
||||||
int raw = 0;
|
int raw = 0;
|
||||||
int type_ok = 0;
|
int type_ok = 0;
|
||||||
|
__u32 nhid = 0;
|
||||||
|
|
||||||
if (cmd != RTM_DELROUTE) {
|
if (cmd != RTM_DELROUTE) {
|
||||||
req.r.rtm_protocol = RTPROT_BOOT;
|
req.r.rtm_protocol = RTPROT_BOOT;
|
||||||
|
|
@ -1358,6 +1363,11 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||||
} else if (strcmp(*argv, "nexthop") == 0) {
|
} else if (strcmp(*argv, "nexthop") == 0) {
|
||||||
nhs_ok = 1;
|
nhs_ok = 1;
|
||||||
break;
|
break;
|
||||||
|
} else if (!strcmp(*argv, "nhid")) {
|
||||||
|
NEXT_ARG();
|
||||||
|
if (get_u32(&nhid, *argv, 0))
|
||||||
|
invarg("\"id\" value is invalid\n", *argv);
|
||||||
|
addattr32(&req.n, sizeof(req), RTA_NH_ID, nhid);
|
||||||
} else if (matches(*argv, "protocol") == 0) {
|
} else if (matches(*argv, "protocol") == 0) {
|
||||||
__u32 prot;
|
__u32 prot;
|
||||||
|
|
||||||
|
|
@ -1520,7 +1530,7 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
|
||||||
req.r.rtm_type == RTN_UNSPEC) {
|
req.r.rtm_type == RTN_UNSPEC) {
|
||||||
if (cmd == RTM_DELROUTE)
|
if (cmd == RTM_DELROUTE)
|
||||||
req.r.rtm_scope = RT_SCOPE_NOWHERE;
|
req.r.rtm_scope = RT_SCOPE_NOWHERE;
|
||||||
else if (!gw_ok && !nhs_ok)
|
else if (!gw_ok && !nhs_ok && !nhid)
|
||||||
req.r.rtm_scope = RT_SCOPE_LINK;
|
req.r.rtm_scope = RT_SCOPE_LINK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,9 @@ replace " } "
|
||||||
.RB "{ " enabled " | " disabled " } ]"
|
.RB "{ " enabled " | " disabled " } ]"
|
||||||
|
|
||||||
.ti -8
|
.ti -8
|
||||||
.IR INFO_SPEC " := " "NH OPTIONS FLAGS" " ["
|
.IR INFO_SPEC " := { " NH " | "
|
||||||
|
.B nhid
|
||||||
|
.IR ID " } " "OPTIONS FLAGS" " ["
|
||||||
.B nexthop
|
.B nexthop
|
||||||
.IR NH " ] ..."
|
.IR NH " ] ..."
|
||||||
|
|
||||||
|
|
@ -686,6 +688,10 @@ Discovery messages. Namely:
|
||||||
- the route has a highest priority
|
- the route has a highest priority
|
||||||
.sp
|
.sp
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI nhid " ID"
|
||||||
|
use nexthop object with given id as nexthop specification.
|
||||||
|
.sp
|
||||||
.TP
|
.TP
|
||||||
.BI encap " ENCAPTYPE ENCAPHDR"
|
.BI encap " ENCAPTYPE ENCAPHDR"
|
||||||
attach tunnel encapsulation attributes to this route.
|
attach tunnel encapsulation attributes to this route.
|
||||||
|
|
@ -1154,6 +1160,11 @@ ip -6 route add 2001:db8:1::/64 encap seg6 mode encap segs 2001:db8:42::1,2001:d
|
||||||
.RS 4
|
.RS 4
|
||||||
Adds an IPv6 route with SRv6 encapsulation and two segments attached.
|
Adds an IPv6 route with SRv6 encapsulation and two segments attached.
|
||||||
.RE
|
.RE
|
||||||
|
.PP
|
||||||
|
ip route add 10.1.1.0/30 nhid 10
|
||||||
|
.RS 4
|
||||||
|
Adds an ipv4 route using nexthop object with id 10.
|
||||||
|
.RE
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.br
|
.br
|
||||||
.BR ip (8)
|
.BR ip (8)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue