Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: Modify how we display/store os description #4220

Merged
merged 1 commit into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
zebra: Modify how we display/store os description
The alias/description of an interface in linux was being
used to override the internal description.  As such let's
fix the display to keep track of both if we have it.

Config in FRR:
!
interface docker0
 description another combination
!
interface enp3s0
 description BAMBOOZLE ME WILL YOU
!

Config in linux:
sharpd@robot ~/f/zebra> ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    alias This is the loopback you cabbage
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 74:d0:2b:9c:16:eb brd ff:ff:ff:ff:ff:ff
    alias HI HI HI

Now the 'show int descr' command:
robot# show int description
Interface       Status  Protocol  Description
docker0         up      down      another combination
enp3s0          up      up        BAMBOOZLE ME WILL YOU
                                  HI HI HI
lo              up      up        This is the loopback you cabbage

Fixes: #4191
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Apr 25, 2019
commit ba5165ecccdbe1ff5aa1ca0203e389ef2c269df5
23 changes: 13 additions & 10 deletions zebra/if_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,9 +690,6 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
ifp->speed = get_iflink_speed(ifp);
ifp->ptm_status = ZEBRA_PTM_STATUS_UNKNOWN;

if (desc)
ifp->desc = XSTRDUP(MTYPE_TMP, desc);

/* Set zebra interface type */
zebra_if_set_ziftype(ifp, zif_type, zif_slave_type);
if (IS_ZEBRA_IF_VRF(ifp))
Expand All @@ -707,6 +704,11 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
zif = (struct zebra_if *)ifp->info;
zif->link_ifindex = link_ifindex;

if (desc) {
XFREE(MTYPE_TMP, zif->desc);
zif->desc = XSTRDUP(MTYPE_TMP, desc);
}

/* Hardware type and address. */
ifp->ll_type = netlink_to_zebra_link_type(ifi->ifi_type);
netlink_interface_update_hw_addr(tb, ifp);
Expand Down Expand Up @@ -1106,7 +1108,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
ifindex_t bond_ifindex = IFINDEX_INTERNAL;
ifindex_t link_ifindex = IFINDEX_INTERNAL;
uint8_t old_hw_addr[INTERFACE_HWADDR_MAX];

struct zebra_if *zif;

zns = zebra_ns_lookup(ns_id);
ifi = NLMSG_DATA(h);
Expand Down Expand Up @@ -1186,12 +1188,6 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
/* See if interface is present. */
ifp = if_lookup_by_name_per_ns(zns, name);

if (ifp) {
XFREE(MTYPE_TMP, ifp->desc);
if (desc)
ifp->desc = XSTRDUP(MTYPE_TMP, desc);
}

if (h->nlmsg_type == RTM_NEWLINK) {
if (tb[IFLA_MASTER]) {
if (slave_kind && (strcmp(slave_kind, "vrf") == 0)
Expand Down Expand Up @@ -1390,6 +1386,13 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
if_delete_update(ifp);
}

zif = ifp->info;
if (zif) {
XFREE(MTYPE_TMP, zif->desc);
if (desc)
zif->desc = XSTRDUP(MTYPE_TMP, desc);
}

return 0;
}

Expand Down
21 changes: 20 additions & 1 deletion zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ static int if_zebra_delete_hook(struct interface *ifp)
list_delete(&rtadv->AdvDNSSLList);
#endif /* HAVE_RTADV */

XFREE(MTYPE_TMP, zebra_if->desc);
THREAD_OFF(zebra_if->speed_update);

XFREE(MTYPE_ZINFO, zebra_if);
Expand Down Expand Up @@ -1303,6 +1304,9 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)

if (ifp->desc)
vty_out(vty, " Description: %s\n", ifp->desc);
if (zebra_if->desc)
vty_out(vty, " OS Description: %s\n", zebra_if->desc);

if (ifp->ifindex == IFINDEX_INTERNAL) {
vty_out(vty, " pseudo interface\n");
return;
Expand Down Expand Up @@ -1696,6 +1700,10 @@ static void if_show_description(struct vty *vty, vrf_id_t vrf_id)
vty_out(vty, "Interface Status Protocol Description\n");
FOR_ALL_INTERFACES (vrf, ifp) {
int len;
struct zebra_if *zif;
bool intf_desc;

intf_desc = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool intf_desc = false ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intf_desc was being set to false once with the bool intf_desc = false why? I am not sure as that was a bit surprising too me. So I just moved it down one line to ensure it was reset at the top of the loop every time.


len = vty_out(vty, "%s", ifp->name);
vty_out(vty, "%*s", (16 - len), " ");
Expand All @@ -1715,8 +1723,19 @@ static void if_show_description(struct vty *vty, vrf_id_t vrf_id)
vty_out(vty, "down down ");
}

if (ifp->desc)
if (ifp->desc) {
intf_desc = true;
vty_out(vty, "%s", ifp->desc);
}
zif = ifp->info;
if (zif && zif->desc) {
vty_out(vty, "%s%s",
intf_desc
? "\n "
: "",
zif->desc);
}

vty_out(vty, "\n");
}
}
Expand Down
3 changes: 3 additions & 0 deletions zebra/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ struct zebra_if {
bool v6_2_v4_ll_neigh_entry;
char neigh_mac[6];
struct in6_addr v6_2_v4_ll_addr6;

/* The description of the interface */
char *desc;
};

DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp),
Expand Down