mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-10 10:49:01 +00:00
Merge pull request #9596 from LabNConsulting/ziemba/printfrr-nexthop
printfrr %pNHcg, %pNHci
This commit is contained in:
commit
827ddd5a1d
@ -191,6 +191,10 @@ Networking data types
|
|||||||
|
|
||||||
``%pNHs``: :frrfmtout:`1.2.3.4 if 15` — same as :c:func:`nexthop2str()`
|
``%pNHs``: :frrfmtout:`1.2.3.4 if 15` — same as :c:func:`nexthop2str()`
|
||||||
|
|
||||||
|
``%pNHcg``: :frrfmtout:`1.2.3.4` — compact gateway only
|
||||||
|
|
||||||
|
``%pNHci``: :frrfmtout:`eth0` — compact interface only
|
||||||
|
|
||||||
.. frrfmt:: %pBD (struct bgp_dest *)
|
.. frrfmt:: %pBD (struct bgp_dest *)
|
||||||
|
|
||||||
:frrfmtout:`fe80::1234/64`
|
:frrfmtout:`fe80::1234/64`
|
||||||
|
@ -936,6 +936,12 @@ int nexthop_str2backups(const char *str, int *num_backups,
|
|||||||
* unreachable (blackhole)
|
* unreachable (blackhole)
|
||||||
* %pNHs
|
* %pNHs
|
||||||
* nexthop2str()
|
* nexthop2str()
|
||||||
|
* %pNHcg
|
||||||
|
* 1.2.3.4
|
||||||
|
* (0-length if no IP address present)
|
||||||
|
* %pNHci
|
||||||
|
* eth0
|
||||||
|
* (0-length if no interface present)
|
||||||
*/
|
*/
|
||||||
printfrr_ext_autoreg_p("NH", printfrr_nh)
|
printfrr_ext_autoreg_p("NH", printfrr_nh)
|
||||||
static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea,
|
static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea,
|
||||||
@ -1026,6 +1032,54 @@ static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
case 'c':
|
||||||
|
ea->fmt++;
|
||||||
|
if (*ea->fmt == 'g') {
|
||||||
|
ea->fmt++;
|
||||||
|
if (!nexthop)
|
||||||
|
return bputs(buf, "(null)");
|
||||||
|
switch (nexthop->type) {
|
||||||
|
case NEXTHOP_TYPE_IPV4:
|
||||||
|
case NEXTHOP_TYPE_IPV4_IFINDEX:
|
||||||
|
ret += bprintfrr(buf, "%pI4",
|
||||||
|
&nexthop->gate.ipv4);
|
||||||
|
break;
|
||||||
|
case NEXTHOP_TYPE_IPV6:
|
||||||
|
case NEXTHOP_TYPE_IPV6_IFINDEX:
|
||||||
|
ret += bprintfrr(buf, "%pI6",
|
||||||
|
&nexthop->gate.ipv6);
|
||||||
|
break;
|
||||||
|
case NEXTHOP_TYPE_IFINDEX:
|
||||||
|
case NEXTHOP_TYPE_BLACKHOLE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (*ea->fmt == 'i') {
|
||||||
|
ea->fmt++;
|
||||||
|
if (!nexthop)
|
||||||
|
return bputs(buf, "(null)");
|
||||||
|
switch (nexthop->type) {
|
||||||
|
case NEXTHOP_TYPE_IFINDEX:
|
||||||
|
ret += bprintfrr(
|
||||||
|
buf, "%s",
|
||||||
|
ifindex2ifname(nexthop->ifindex,
|
||||||
|
nexthop->vrf_id));
|
||||||
|
break;
|
||||||
|
case NEXTHOP_TYPE_IPV4:
|
||||||
|
case NEXTHOP_TYPE_IPV4_IFINDEX:
|
||||||
|
case NEXTHOP_TYPE_IPV6:
|
||||||
|
case NEXTHOP_TYPE_IPV6_IFINDEX:
|
||||||
|
if (nexthop->ifindex)
|
||||||
|
ret += bprintfrr(
|
||||||
|
buf, "%s",
|
||||||
|
ifindex2ifname(
|
||||||
|
nexthop->ifindex,
|
||||||
|
nexthop->vrf_id));
|
||||||
|
break;
|
||||||
|
case NEXTHOP_TYPE_BLACKHOLE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "lib/printfrr.h"
|
#include "lib/printfrr.h"
|
||||||
#include "lib/memory.h"
|
#include "lib/memory.h"
|
||||||
#include "lib/prefix.h"
|
#include "lib/prefix.h"
|
||||||
|
#include "lib/nexthop.h"
|
||||||
|
|
||||||
static int errors;
|
static int errors;
|
||||||
|
|
||||||
@ -253,5 +254,25 @@ int main(int argc, char **argv)
|
|||||||
printchk("\"\"", "%pSQqn", (char *)NULL);
|
printchk("\"\"", "%pSQqn", (char *)NULL);
|
||||||
printchk("(null)", "%pSQq", (char *)NULL);
|
printchk("(null)", "%pSQq", (char *)NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* %pNH<foo> tests
|
||||||
|
*
|
||||||
|
* gateway addresses only for now: interfaces require more setup
|
||||||
|
*/
|
||||||
|
printchk("(null)", "%pNHcg", NULL);
|
||||||
|
printchk("(null)", "%pNHci", NULL);
|
||||||
|
|
||||||
|
struct nexthop nh;
|
||||||
|
|
||||||
|
memset(&nh, 0, sizeof(nh));
|
||||||
|
|
||||||
|
nh.type = NEXTHOP_TYPE_IPV4;
|
||||||
|
inet_aton("3.2.1.0", &nh.gate.ipv4);
|
||||||
|
printchk("3.2.1.0", "%pNHcg", &nh);
|
||||||
|
|
||||||
|
nh.type = NEXTHOP_TYPE_IPV6;
|
||||||
|
inet_pton(AF_INET6, "fe2c::34", &nh.gate.ipv6);
|
||||||
|
printchk("fe2c::34", "%pNHcg", &nh);
|
||||||
|
|
||||||
return !!errors;
|
return !!errors;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user