Skip to content

Commit

Permalink
pbrd: Fix the way IPv6 address is formatted
Browse files Browse the repository at this point in the history
Issue:
issue is how the IPv6 address is formatted when being printed in PBR.
Format specifier %pFX  not be the correct one to use for printing IPv6
addresses.

Fix:
1.In C, to print IPv6 addresses, typically use the inet_ntop function to
convert the
 binary address into a human-readable string based on the address
 family.

 2. During frr reload - preserving the full IPv6 address along with its
    prefix length

 Testing Done:
 precommit, pbr map with ipv6 and ipv4 rule

 Ticket: #3498263
 Signed-off-by: Rajesh Varatharaj <rvaratharaj@nvidia.com>
  • Loading branch information
routingrocks authored and krishna-samy committed Jan 3, 2025
1 parent fb9ee9f commit 83aa6b3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
38 changes: 33 additions & 5 deletions pbrd/pbr_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,8 @@ static void vty_show_pbrms(struct vty *vty,
const struct pbr_map_sequence *pbrms, bool detail)
{
char rbuf[64];
char src_str[INET6_ADDRSTRLEN];
char dst_str[INET6_ADDRSTRLEN];

if (pbrms->reason)
pbr_map_reason_string(pbrms->reason, rbuf, sizeof(rbuf));
Expand All @@ -1540,11 +1542,37 @@ static void vty_show_pbrms(struct vty *vty,
p = getprotobynumber(pbrms->ip_proto);
vty_out(vty, " IP Protocol Match: %s\n", p->p_name);
}

if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP))
vty_out(vty, " SRC IP Match: %pFX\n", pbrms->src);
if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP))
vty_out(vty, " DST IP Match: %pFX\n", pbrms->dst);
if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_IP)) {
if (pbrms->src->family == AF_INET) {
if (inet_ntop(AF_INET, &pbrms->src->u.prefix4, src_str, INET_ADDRSTRLEN) !=
NULL) {
vty_out(vty, " SRC IP Match: %s/%d\n", src_str,
pbrms->src->prefixlen);
}
} else if (pbrms->src->family == AF_INET6) {
// ipv6 addr
if (inet_ntop(AF_INET6, &pbrms->src->u.prefix6, src_str,
INET6_ADDRSTRLEN) != NULL) {
vty_out(vty, " SRC IP Match: %s/%d\n", src_str,
pbrms->src->prefixlen);
}
}
}
if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_DST_IP)) {
if (pbrms->dst->family == AF_INET) {
if (inet_ntop(AF_INET, &pbrms->dst->u.prefix4, dst_str, INET_ADDRSTRLEN) !=
NULL) {
vty_out(vty, " DST IP Match: %s/%d\n", dst_str,
pbrms->dst->prefixlen);
}
} else if (pbrms->dst->family == AF_INET6) {
if (inet_ntop(AF_INET6, &pbrms->dst->u.prefix6, dst_str,
INET6_ADDRSTRLEN) != NULL) {
vty_out(vty, " DST IP Match: %s/%d\n", dst_str,
pbrms->dst->prefixlen);
}
}
}

if (CHECK_FLAG(pbrms->filter_bm, PBR_FILTER_SRC_PORT))
vty_out(vty, " SRC Port Match: %u\n", pbrms->src_prt);
Expand Down
6 changes: 4 additions & 2 deletions tools/frr-reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ def get_normalized_bgp_default(line):
def get_normalized_mac_ip_line(line):
if line.startswith("evpn mh es"):
return get_normalized_es_id(line)

if not "ipv6 add" in line:
"""
pbr map match should preserve Full Address
"""
if not "ipv6 add" or not "match" in line:
return get_normalized_ipv6_line(line)

return line
Expand Down

0 comments on commit 83aa6b3

Please sign in to comment.