From 9867746afefbead8d36cda32a0453f51e4f34362 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 12 Jul 2016 15:09:25 -0400 Subject: [PATCH] pimd: Refactor 'struct static_route' to use channel_oil The 'struct static_route' data structure duplicated a decent bit of what is the in the struct channel_oil. Refactor. This will set us up for further cleanup. Signed-off-by: Donald Sharp --- pimd/pim_cmd.c | 23 ++++++++++--------- pimd/pim_static.c | 58 ++++++++++++++++++++++++----------------------- pimd/pim_static.h | 4 +--- pimd/pim_vty.c | 1 + pimd/pimd.h | 1 - 5 files changed, 44 insertions(+), 43 deletions(-) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 68446572eb..3924758ddb 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -30,6 +30,7 @@ #include "zclient.h" #include "pimd.h" +#include "pim_mroute.h" #include "pim_cmd.h" #include "pim_iface.h" #include "pim_vty.h" @@ -1637,12 +1638,12 @@ static void static_mroute_add_all() struct static_route *s_route; for (ALL_LIST_ELEMENTS_RO(qpim_static_route_list, node, s_route)) { - if (pim_mroute_add(&s_route->mc)) { + if (pim_mroute_add(&s_route->c_oil.oil)) { /* just log warning */ char source_str[100]; char group_str[100]; - pim_inet4_dump("", s_route->mc.mfcc_origin, source_str, sizeof(source_str)); - pim_inet4_dump("", s_route->mc.mfcc_mcastgrp, group_str, sizeof(group_str)); + pim_inet4_dump("", s_route->c_oil.oil.mfcc_origin, source_str, sizeof(source_str)); + pim_inet4_dump("", s_route->c_oil.oil.mfcc_mcastgrp, group_str, sizeof(group_str)); zlog_warn("%s %s: (S,G)=(%s,%s) failure writing MFC", __FILE__, __PRETTY_FUNCTION__, source_str, group_str); @@ -1656,12 +1657,12 @@ static void static_mroute_del_all() struct static_route *s_route; for (ALL_LIST_ELEMENTS_RO(qpim_static_route_list, node, s_route)) { - if (pim_mroute_del(&s_route->mc)) { + if (pim_mroute_del(&s_route->c_oil.oil)) { /* just log warning */ char source_str[100]; char group_str[100]; - pim_inet4_dump("", s_route->mc.mfcc_origin, source_str, sizeof(source_str)); - pim_inet4_dump("", s_route->mc.mfcc_mcastgrp, group_str, sizeof(group_str)); + pim_inet4_dump("", s_route->c_oil.oil.mfcc_origin, source_str, sizeof(source_str)); + pim_inet4_dump("", s_route->c_oil.oil.mfcc_mcastgrp, group_str, sizeof(group_str)); zlog_warn("%s %s: (S,G)=(%s,%s) failure clearing MFC", __FILE__, __PRETTY_FUNCTION__, source_str, group_str); @@ -2256,7 +2257,7 @@ static void show_mroute(struct vty *vty) ifp_in = pim_if_find_by_vif_index(s_route->iif); ifp_out = pim_if_find_by_vif_index(oif_vif_index); - pim_time_uptime(oif_uptime, sizeof(oif_uptime), now - s_route->creation[oif_vif_index]); + pim_time_uptime(oif_uptime, sizeof(oif_uptime), now - s_route->c_oil.oif_creation[oif_vif_index]); proto[0] = '\0'; strcat(proto, "S"); @@ -2340,11 +2341,11 @@ static void show_mroute_count(struct vty *vty) struct sioc_sg_req sgreq; memset(&sgreq, 0, sizeof(sgreq)); - sgreq.src = s_route->mc.mfcc_origin; - sgreq.grp = s_route->mc.mfcc_mcastgrp; + sgreq.src = s_route->c_oil.oil.mfcc_origin; + sgreq.grp = s_route->c_oil.oil.mfcc_mcastgrp; - pim_inet4_dump("", s_route->mc.mfcc_mcastgrp, group_str, sizeof(group_str)); - pim_inet4_dump("", s_route->mc.mfcc_origin, source_str, sizeof(source_str)); + pim_inet4_dump("", s_route->c_oil.oil.mfcc_mcastgrp, group_str, sizeof(group_str)); + pim_inet4_dump("", s_route->c_oil.oil.mfcc_origin, source_str, sizeof(source_str)); if (ioctl(qpim_mroute_socket_fd, SIOCGETSGCNT, &sgreq)) { int e = errno; diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 47a34daf48..84b026be11 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -24,15 +24,16 @@ #include "vty.h" #include "if.h" +#include "log.h" +#include "memory.h" +#include "linklist.h" +#include "pimd.h" +#include "pim_oil.h" #include "pim_static.h" #include "pim_time.h" #include "pim_str.h" -#include "pimd.h" #include "pim_iface.h" -#include "log.h" -#include "memory.h" -#include "linklist.h" void pim_static_route_free(struct static_route *s_route) { @@ -66,12 +67,12 @@ static struct static_route *static_route_new(unsigned int iif, s_route->source = source; s_route->iif = iif; s_route->oif_ttls[oif] = 1; - s_route->oif_count = 1; - s_route->mc.mfcc_origin = source; - s_route->mc.mfcc_mcastgrp = group; - s_route->mc.mfcc_parent = iif; - s_route->mc.mfcc_ttls[oif] = 1; - s_route->creation[oif] = pim_time_monotonic_sec(); + s_route->c_oil.oil_ref_count = 1; + s_route->c_oil.oil.mfcc_origin = source; + s_route->c_oil.oil.mfcc_mcastgrp = group; + s_route->c_oil.oil.mfcc_parent = iif; + s_route->c_oil.oil.mfcc_ttls[oif] = 1; + s_route->c_oil.oif_creation[oif] = pim_time_monotonic_sec(); return s_route; } @@ -138,30 +139,30 @@ int pim_static_add(struct interface *iif, struct interface *oif, struct in_addr /* Route exists and has the same input interface, but adding a new output interface */ if (s_route->iif == iif_index) { s_route->oif_ttls[oif_index] = 1; - s_route->mc.mfcc_ttls[oif_index] = 1; - s_route->creation[oif_index] = pim_time_monotonic_sec(); - ++s_route->oif_count; + s_route->c_oil.oil.mfcc_ttls[oif_index] = 1; + s_route->c_oil.oif_creation[oif_index] = pim_time_monotonic_sec(); + ++s_route->c_oil.oil_ref_count; } else { /* input interface changed */ s_route->iif = iif_index; - s_route->mc.mfcc_parent = iif_index; + s_route->c_oil.oil.mfcc_parent = iif_index; #ifdef PIM_ENFORCE_LOOPFREE_MFC /* check to make sure the new input was not an old output */ if (s_route->oif_ttls[iif_index]) { s_route->oif_ttls[iif_index] = 0; - s_route->creation[iif_index] = 0; - s_route->mc.mfcc_ttls[iif_index] = 0; - --s_route->oif_count; + s_route->c_oil.oif_creation[iif_index] = 0; + s_route->c_oil.oil.mfcc_ttls[iif_index] = 0; + --s_route->c_oil.oil_ref_count; } #endif /* now add the new output, if it is new */ if (!s_route->oif_ttls[oif_index]) { s_route->oif_ttls[oif_index] = 1; - s_route->creation[oif_index] = pim_time_monotonic_sec(); - s_route->mc.mfcc_ttls[oif_index] = 1; - ++s_route->oif_count; + s_route->c_oil.oif_creation[oif_index] = pim_time_monotonic_sec(); + s_route->c_oil.oil.mfcc_ttls[oif_index] = 1; + ++s_route->c_oil.oil_ref_count; } } @@ -175,7 +176,7 @@ int pim_static_add(struct interface *iif, struct interface *oif, struct in_addr listnode_add(qpim_static_route_list, s_route); } - if (pim_mroute_add(&(s_route->mc))) + if (pim_mroute_add(&s_route->c_oil.oil)) { char gifaddr_str[100]; char sifaddr_str[100]; @@ -245,11 +246,12 @@ int pim_static_del(struct interface *iif, struct interface *oif, struct in_addr s_route->source.s_addr == source.s_addr && s_route->oif_ttls[oif_index]) { s_route->oif_ttls[oif_index] = 0; - s_route->mc.mfcc_ttls[oif_index] = 0; - --s_route->oif_count; + s_route->c_oil.oil.mfcc_ttls[oif_index] = 0; + --s_route->c_oil.oil_ref_count; /* If there are no more outputs then delete the whole route, otherwise set the route with the new outputs */ - if (s_route->oif_count <= 0 ? pim_mroute_del(&s_route->mc) : pim_mroute_add(&s_route->mc)) { + if (s_route->c_oil.oil_ref_count <= 0 ? + pim_mroute_del(&s_route->c_oil.oil) : pim_mroute_add(&s_route->c_oil.oil)) { char gifaddr_str[100]; char sifaddr_str[100]; pim_inet4_dump("", group, gifaddr_str, sizeof(gifaddr_str)); @@ -262,15 +264,15 @@ int pim_static_del(struct interface *iif, struct interface *oif, struct in_addr sifaddr_str); s_route->oif_ttls[oif_index] = 1; - s_route->mc.mfcc_ttls[oif_index] = 1; - ++s_route->oif_count; + s_route->c_oil.oil.mfcc_ttls[oif_index] = 1; + ++s_route->c_oil.oil_ref_count; return -1; } - s_route->creation[oif_index] = 0; + s_route->c_oil.oif_creation[oif_index] = 0; - if (s_route->oif_count <= 0) { + if (s_route->c_oil.oil_ref_count <= 0) { listnode_delete(qpim_static_route_list, s_route); pim_static_route_free(s_route); } diff --git a/pimd/pim_static.h b/pimd/pim_static.h index b3be09e913..ff89fb150e 100644 --- a/pimd/pim_static.h +++ b/pimd/pim_static.h @@ -32,11 +32,9 @@ struct static_route { struct in_addr group; struct in_addr source; + struct channel_oil c_oil; unsigned int iif; unsigned char oif_ttls[MAXVIFS]; - int oif_count; - struct mfcctl mc; - time_t creation[MAXVIFS]; }; void pim_static_route_free(struct static_route *s_route); diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index beb0622a3f..f1c8930856 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -33,6 +33,7 @@ #include "pim_str.h" #include "pim_ssmpingd.h" #include "pim_pim.h" +#include "pim_oil.h" #include "pim_static.h" int pim_debug_config_write(struct vty *vty) diff --git a/pimd/pimd.h b/pimd/pimd.h index c5fec76675..0a376aa905 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -25,7 +25,6 @@ #include -#include "pim_mroute.h" #include "pim_assert.h" #define PIMD_PROGNAME "pimd" -- 2.39.5