diff options
| author | Sharath Ramamurthy <sramamurthy@nvidia.com> | 2021-07-27 13:14:15 +0530 |
|---|---|---|
| committer | Stephen Worley <sworley@nvidia.com> | 2023-02-13 18:12:04 -0500 |
| commit | 8d30ff3b5ef815ad5cab092f2ce6dc28ab5e3421 (patch) | |
| tree | dba0c94cddbbb5cf0303e16e5a8fa208ba20feea /zebra/interface.c | |
| parent | 7809df20643ab9f731930dcef9661a70ef261e5b (diff) | |
zebra: data structure changes for single vxlan device
This changeset introduces the data structure changes needed for
single vxlan device functionality. A new struct zebra_vxlan_vni_info
encodes the iftype and vni information for vxlan device.
The change addresses related access changes of the new data structure
fields from different files
zebra_vty is modified to take care of the vni dump information according
to the new vni data structure for vxlan devices.
Signed-off-by: Sharath Ramamurthy <sramamurthy@nvidia.com>
Diffstat (limited to 'zebra/interface.c')
| -rw-r--r-- | zebra/interface.c | 168 |
1 files changed, 115 insertions, 53 deletions
diff --git a/zebra/interface.c b/zebra/interface.c index 59563834ef..81abb13b75 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1889,6 +1889,118 @@ static inline bool if_is_protodown_applicable(struct interface *ifp) return true; } +static void zebra_vxlan_if_vni_dump_vty(struct vty *vty, + struct zebra_vxlan_vni *vni) +{ + vty_out(vty, " VxLAN Id %u", vni->vni); + if (vni->access_vlan) + vty_out(vty, " Access VLAN Id %u\n", vni->access_vlan); + + if (vni->mcast_grp.s_addr != INADDR_ANY) + vty_out(vty, " Mcast Group %s", inet_ntoa(vni->mcast_grp)); +} + +static void zebra_vxlan_if_vni_dump_vty_json(struct zebra_vxlan_vni *vni, + json_object *json_if) +{ + json_object_int_add(json_if, "vxlanId", vni->vni); + if (vni->access_vlan) + json_object_int_add(json_if, "accessVlanId", vni->access_vlan); + + if (vni->mcast_grp.s_addr != INADDR_ANY) + json_object_string_addf(json_if, "mcastGroup", "%pI4", + &vni->mcast_grp); +} + +struct vxlan_if_dump_ctx { + struct vty *vty; + json_object *json_if; +}; + +static void zebra_vxlan_if_vni_hash_dump_vty(struct hash_bucket *bucket, + void *ctxt) +{ + struct vty *vty; + struct json_object *json_if; + struct zebra_vxlan_vni *vni; + + vni = (struct zebra_vxlan_vni *)bucket->data; + vty = ((struct vxlan_if_dump_ctx *)ctxt)->vty; + json_if = ((struct vxlan_if_dump_ctx *)ctxt)->json_if; + + if (json_if) + zebra_vxlan_if_vni_dump_vty_json(vni, json_if); + else + zebra_vxlan_if_vni_dump_vty(vty, vni); +} + +static void zebra_vxlan_if_dump_vty(struct vty *vty, struct zebra_if *zebra_if) +{ + struct vxlan_if_dump_ctx dump_ctx; + struct zebra_l2info_vxlan *vxlan_info; + struct zebra_vxlan_vni_info *vni_info; + + vxlan_info = &zebra_if->l2info.vxl; + vni_info = &vxlan_info->vni_info; + + if (vxlan_info->vtep_ip.s_addr != INADDR_ANY) + vty_out(vty, " VTEP IP: %s", inet_ntoa(vxlan_info->vtep_ip)); + + if (vxlan_info->ifindex_link && (vxlan_info->link_nsid != NS_UNKNOWN)) { + struct interface *ifp; + + ifp = if_lookup_by_index_per_ns( + zebra_ns_lookup(vxlan_info->link_nsid), + vxlan_info->ifindex_link); + vty_out(vty, " Link Interface %s", + ifp == NULL ? "Unknown" : ifp->name); + } + + if (IS_ZEBRA_VXLAN_IF_VNI(zebra_if)) { + zebra_vxlan_if_vni_dump_vty(vty, &vni_info->vni); + } else { + dump_ctx.json_if = NULL; + dump_ctx.vty = vty; + hash_iterate(vni_info->vni_table, + zebra_vxlan_if_vni_hash_dump_vty, &dump_ctx); + } + + vty_out(vty, "\n"); +} + +static void zebra_vxlan_if_dump_vty_json(struct zebra_if *zebra_if, + json_object *json_if) +{ + struct vxlan_if_dump_ctx dump_ctx; + struct zebra_l2info_vxlan *vxlan_info; + struct zebra_vxlan_vni_info *vni_info; + + vxlan_info = &zebra_if->l2info.vxl; + vni_info = &vxlan_info->vni_info; + + if (vxlan_info->vtep_ip.s_addr != INADDR_ANY) + json_object_string_addf(json_if, "vtepIp", "%pI4", + &vxlan_info->vtep_ip); + + if (vxlan_info->ifindex_link && (vxlan_info->link_nsid != NS_UNKNOWN)) { + struct interface *ifp; + + ifp = if_lookup_by_index_per_ns( + zebra_ns_lookup(vxlan_info->link_nsid), + vxlan_info->ifindex_link); + json_object_string_add(json_if, "linkInterface", + ifp == NULL ? "Unknown" : ifp->name); + } + + if (IS_ZEBRA_VXLAN_IF_VNI(zebra_if)) { + zebra_vxlan_if_vni_dump_vty_json(&vni_info->vni, json_if); + } else { + dump_ctx.json_if = json_if; + hash_iterate(vni_info->vni_table, + zebra_vxlan_if_vni_hash_dump_vty, &dump_ctx); + } +} + /* Interface's information print out to vty interface. */ static void if_dump_vty(struct vty *vty, struct interface *ifp) { @@ -1997,42 +2109,15 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) zebra_zifslavetype_2str(zebra_if->zif_slave_type)); if (IS_ZEBRA_IF_BRIDGE(ifp)) { - struct zebra_l2info_bridge *bridge_info; - - bridge_info = &zebra_if->l2info.br; vty_out(vty, " Bridge VLAN-aware: %s\n", - bridge_info->vlan_aware ? "yes" : "no"); + IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(zebra_if) ? "yes" : "no"); } else if (IS_ZEBRA_IF_VLAN(ifp)) { struct zebra_l2info_vlan *vlan_info; vlan_info = &zebra_if->l2info.vl; vty_out(vty, " VLAN Id %u\n", vlan_info->vid); } else if (IS_ZEBRA_IF_VXLAN(ifp)) { - struct zebra_l2info_vxlan *vxlan_info; - - vxlan_info = &zebra_if->l2info.vxl; - vty_out(vty, " VxLAN Id %u", vxlan_info->vni); - if (vxlan_info->vtep_ip.s_addr != INADDR_ANY) - vty_out(vty, " VTEP IP: %pI4", - &vxlan_info->vtep_ip); - if (vxlan_info->access_vlan) - vty_out(vty, " Access VLAN Id %u\n", - vxlan_info->access_vlan); - if (vxlan_info->mcast_grp.s_addr != INADDR_ANY) - vty_out(vty, " Mcast Group %pI4", - &vxlan_info->mcast_grp); - if (vxlan_info->ifindex_link && - (vxlan_info->link_nsid != NS_UNKNOWN)) { - struct interface *ifp; - - ifp = if_lookup_by_index_per_ns( - zebra_ns_lookup(vxlan_info->link_nsid), - vxlan_info->ifindex_link); - vty_out(vty, " Link Interface %s", - ifp == NULL ? "Unknown" : - ifp->name); - } - vty_out(vty, "\n"); + zebra_vxlan_if_dump_vty(vty, zebra_if); } else if (IS_ZEBRA_IF_GRE(ifp)) { struct zebra_l2info_gre *gre_info; @@ -2359,30 +2444,7 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp, vlan_info = &zebra_if->l2info.vl; json_object_int_add(json_if, "vlanId", vlan_info->vid); } else if (IS_ZEBRA_IF_VXLAN(ifp)) { - struct zebra_l2info_vxlan *vxlan_info; - - vxlan_info = &zebra_if->l2info.vxl; - json_object_int_add(json_if, "vxlanId", vxlan_info->vni); - if (vxlan_info->vtep_ip.s_addr != INADDR_ANY) - json_object_string_addf(json_if, "vtepIp", "%pI4", - &vxlan_info->vtep_ip); - if (vxlan_info->access_vlan) - json_object_int_add(json_if, "accessVlanId", - vxlan_info->access_vlan); - if (vxlan_info->mcast_grp.s_addr != INADDR_ANY) - json_object_string_addf(json_if, "mcastGroup", "%pI4", - &vxlan_info->mcast_grp); - if (vxlan_info->ifindex_link - && (vxlan_info->link_nsid != NS_UNKNOWN)) { - struct interface *ifp; - - ifp = if_lookup_by_index_per_ns( - zebra_ns_lookup(vxlan_info->link_nsid), - vxlan_info->ifindex_link); - json_object_string_add(json_if, "linkInterface", - ifp == NULL ? "Unknown" - : ifp->name); - } + zebra_vxlan_if_dump_vty_json(zebra_if, json_if); } else if (IS_ZEBRA_IF_GRE(ifp)) { struct zebra_l2info_gre *gre_info; |
