]> git.puffer.fish Git - mirror/frr.git/commitdiff
isisd: reduce code duplication for levels
authorChristian Franke <chris@opensourcerouting.org>
Wed, 10 Oct 2018 09:16:39 +0000 (11:16 +0200)
committerChristian Franke <chris@opensourcerouting.org>
Tue, 4 Dec 2018 11:49:25 +0000 (12:49 +0100)
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
isisd/isis_circuit.c
isisd/isis_dr.c
isisd/isis_dr.h
isisd/isis_events.c
isisd/isis_pdu.c
isisd/isis_pdu.h

index 4c095c26d1d3315b167b8d2fb35b4e3b9da69e66..20094fb6236968c39e5961167e135bd0f5d96d97 100644 (file)
@@ -615,37 +615,31 @@ int isis_circuit_up(struct isis_circuit *circuit)
 
                /* 8.4.1 a) commence sending of IIH PDUs */
 
-               if (circuit->is_type & IS_LEVEL_1) {
-                       thread_add_event(master, send_lan_l1_hello, circuit, 0,
-                                        NULL);
-                       circuit->u.bc.lan_neighs[0] = list_new();
-               }
+               for (int level = ISIS_LEVEL1; level <= ISIS_LEVEL2; level++) {
+                       if (!(circuit->is_type & level))
+                               continue;
 
-               if (circuit->is_type & IS_LEVEL_2) {
-                       thread_add_event(master, send_lan_l2_hello, circuit, 0,
-                                        NULL);
-                       circuit->u.bc.lan_neighs[1] = list_new();
+                       thread_add_event(master, send_hello_cb,
+                                        &circuit->level_arg[level - 1], 0,
+                                        &circuit->u.bc.t_send_lan_hello[level - 1]);
+                       circuit->u.bc.lan_neighs[level - 1] = list_new();
+
+                       thread_add_timer(master, isis_run_dr,
+                                        &circuit->level_arg[level - 1],
+                                        2 * circuit->hello_interval[level - 1],
+                                        &circuit->u.bc.t_run_dr[level - 1]);
                }
 
                /* 8.4.1 b) FIXME: solicit ES - 8.4.6 */
                /* 8.4.1 c) FIXME: listen for ESH PDUs */
-
-               /* 8.4.1 d) */
-               /* dr election will commence in... */
-               if (circuit->is_type & IS_LEVEL_1)
-                       thread_add_timer(master, isis_run_dr_l1, circuit,
-                                        2 * circuit->hello_interval[0],
-                                        &circuit->u.bc.t_run_dr[0]);
-               if (circuit->is_type & IS_LEVEL_2)
-                       thread_add_timer(master, isis_run_dr_l2, circuit,
-                                        2 * circuit->hello_interval[1],
-                                        &circuit->u.bc.t_run_dr[1]);
        } else if (circuit->circ_type == CIRCUIT_T_P2P) {
                /* initializing the hello send threads
                 * for a ptp IF
                 */
                circuit->u.p2p.neighbor = NULL;
-               thread_add_event(master, send_p2p_hello, circuit, 0, NULL);
+               thread_add_event(master, send_hello_cb,
+                                &circuit->level_arg[0], 0,
+                                &circuit->u.p2p.t_send_p2p_hello);
        }
 
        /* initializing PSNP timers */
index f71fe9555b8da9b7e1b64c24591a3fecdd840522..b2ec8ae594894ca7201acf919b593355fcc4c043 100644 (file)
@@ -62,35 +62,28 @@ const char *isis_disflag2string(int disflag)
        return NULL; /* not reached */
 }
 
-int isis_run_dr_l1(struct thread *thread)
+int isis_run_dr(struct thread *thread)
 {
-       struct isis_circuit *circuit;
+       struct isis_circuit_arg *arg = THREAD_ARG(thread);
 
-       circuit = THREAD_ARG(thread);
-       assert(circuit);
-
-       if (circuit->u.bc.run_dr_elect[0])
-               zlog_warn("isis_run_dr(): run_dr_elect already set for l1");
-
-       circuit->u.bc.t_run_dr[0] = NULL;
-       circuit->u.bc.run_dr_elect[0] = 1;
+       assert(arg);
 
-       return ISIS_OK;
-}
+       struct isis_circuit *circuit = arg->circuit;
+       int level = arg->level;
 
-int isis_run_dr_l2(struct thread *thread)
-{
-       struct isis_circuit *circuit;
-
-       circuit = THREAD_ARG(thread);
        assert(circuit);
 
-       if (circuit->u.bc.run_dr_elect[1])
-               zlog_warn("isis_run_dr(): run_dr_elect already set for l2");
+       if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
+               zlog_warn("%s: scheduled for non broadcast circuit from %s:%d",
+                         __func__, thread->schedfrom, thread->schedfrom_line);
+               return ISIS_WARNING;
+       }
 
+       if (circuit->u.bc.run_dr_elect[level - 1])
+               zlog_warn("isis_run_dr(): run_dr_elect already set for l%d", level);
 
-       circuit->u.bc.t_run_dr[1] = NULL;
-       circuit->u.bc.run_dr_elect[1] = 1;
+       circuit->u.bc.t_run_dr[level - 1] = NULL;
+       circuit->u.bc.run_dr_elect[level - 1] = 1;
 
        return ISIS_OK;
 }
@@ -241,12 +234,6 @@ int isis_dr_resign(struct isis_circuit *circuit, int level)
        if (level == 1) {
                memset(circuit->u.bc.l1_desig_is, 0, ISIS_SYS_ID_LEN + 1);
 
-               THREAD_TIMER_OFF(circuit->t_send_csnp[0]);
-
-               thread_add_timer(master, isis_run_dr_l1, circuit,
-                                2 * circuit->hello_interval[0],
-                                &circuit->u.bc.t_run_dr[0]);
-
                thread_add_timer(master, send_l1_psnp, circuit,
                                 isis_jitter(circuit->psnp_interval[level - 1],
                                             PSNP_JITTER),
@@ -254,18 +241,20 @@ int isis_dr_resign(struct isis_circuit *circuit, int level)
        } else {
                memset(circuit->u.bc.l2_desig_is, 0, ISIS_SYS_ID_LEN + 1);
 
-               THREAD_TIMER_OFF(circuit->t_send_csnp[1]);
-
-               thread_add_timer(master, isis_run_dr_l2, circuit,
-                                2 * circuit->hello_interval[1],
-                                &circuit->u.bc.t_run_dr[1]);
-
                thread_add_timer(master, send_l2_psnp, circuit,
                                 isis_jitter(circuit->psnp_interval[level - 1],
                                             PSNP_JITTER),
                                 &circuit->t_send_psnp[1]);
        }
 
+       THREAD_TIMER_OFF(circuit->t_send_csnp[level - 1]);
+
+       thread_add_timer(master, isis_run_dr,
+                        &circuit->level_arg[level - 1],
+                        2 * circuit->hello_interval[level - 1],
+                        &circuit->u.bc.t_run_dr[level - 1]);
+
+
        thread_add_event(master, isis_event_dis_status_change, circuit, 0,
                         NULL);
 
@@ -281,14 +270,10 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
 
        /* Lets keep a pause in DR election */
        circuit->u.bc.run_dr_elect[level - 1] = 0;
-       if (level == 1)
-               thread_add_timer(master, isis_run_dr_l1, circuit,
-                                2 * circuit->hello_interval[0],
-                                &circuit->u.bc.t_run_dr[0]);
-       else
-               thread_add_timer(master, isis_run_dr_l2, circuit,
-                                2 * circuit->hello_interval[1],
-                                &circuit->u.bc.t_run_dr[1]);
+       thread_add_timer(master, isis_run_dr,
+                        &circuit->level_arg[level - 1],
+                        2 * circuit->hello_interval[level - 1],
+                        &circuit->u.bc.t_run_dr[level - 1]);
        circuit->u.bc.is_dr[level - 1] = 1;
 
        if (level == 1) {
@@ -307,11 +292,6 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
                   thread_cancel (circuit->t_send_l1_psnp); */
                lsp_generate_pseudo(circuit, 1);
 
-               THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[0]);
-               thread_add_timer(master, isis_run_dr_l1, circuit,
-                                2 * circuit->hello_interval[0],
-                                &circuit->u.bc.t_run_dr[0]);
-
                thread_add_timer(master, send_l1_csnp, circuit,
                                 isis_jitter(circuit->csnp_interval[level - 1],
                                             CSNP_JITTER),
@@ -333,11 +313,6 @@ int isis_dr_commence(struct isis_circuit *circuit, int level)
                   thread_cancel (circuit->t_send_l1_psnp); */
                lsp_generate_pseudo(circuit, 2);
 
-               THREAD_TIMER_OFF(circuit->u.bc.t_run_dr[1]);
-               thread_add_timer(master, isis_run_dr_l2, circuit,
-                                2 * circuit->hello_interval[1],
-                                &circuit->u.bc.t_run_dr[1]);
-
                thread_add_timer(master, send_l2_csnp, circuit,
                                 isis_jitter(circuit->csnp_interval[level - 1],
                                             CSNP_JITTER),
index ed26558b0826ca2c1e0f97d8bd5d2e0e5fc93393..5cab985d4b35c0b41c0c023232c7ae9b9a215262 100644 (file)
@@ -24,8 +24,7 @@
 #ifndef _ZEBRA_ISIS_DR_H
 #define _ZEBRA_ISIS_DR_H
 
-int isis_run_dr_l1(struct thread *thread);
-int isis_run_dr_l2(struct thread *thread);
+int isis_run_dr(struct thread *thread);
 int isis_dr_elect(struct isis_circuit *circuit, int level);
 int isis_dr_resign(struct isis_circuit *circuit, int level);
 int isis_dr_commence(struct isis_circuit *circuit, int level);
index 9f58c24b71be856585f10f5c091f1ff485ab4093..db197c7beadbf51f90e05335da2aed945cbe1ff9 100644 (file)
@@ -77,47 +77,34 @@ void isis_event_circuit_state_change(struct isis_circuit *circuit,
 
 static void circuit_commence_level(struct isis_circuit *circuit, int level)
 {
-       if (level == 1) {
-               if (!circuit->is_passive)
+       if (!circuit->is_passive) {
+               if (level == 1) {
                        thread_add_timer(master, send_l1_psnp, circuit,
                                         isis_jitter(circuit->psnp_interval[0],
                                                     PSNP_JITTER),
                                         &circuit->t_send_psnp[0]);
-
-               if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
-                       thread_add_timer(master, isis_run_dr_l1, circuit,
-                                        2 * circuit->hello_interval[0],
-                                        &circuit->u.bc.t_run_dr[0]);
-
-                       thread_add_timer(master, send_lan_l1_hello, circuit,
-                                        isis_jitter(circuit->hello_interval[0],
-                                                    IIH_JITTER),
-                                        &circuit->u.bc.t_send_lan_hello[0]);
-
-                       circuit->u.bc.lan_neighs[0] = list_new();
-               }
-       } else {
-               if (!circuit->is_passive)
+               } else {
                        thread_add_timer(master, send_l2_psnp, circuit,
                                         isis_jitter(circuit->psnp_interval[1],
                                                     PSNP_JITTER),
                                         &circuit->t_send_psnp[1]);
-
-               if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
-                       thread_add_timer(master, isis_run_dr_l2, circuit,
-                                        2 * circuit->hello_interval[1],
-                                        &circuit->u.bc.t_run_dr[1]);
-
-                       thread_add_timer(master, send_lan_l2_hello, circuit,
-                                        isis_jitter(circuit->hello_interval[1],
-                                                    IIH_JITTER),
-                                        &circuit->u.bc.t_send_lan_hello[1]);
-
-                       circuit->u.bc.lan_neighs[1] = list_new();
                }
        }
 
-       return;
+       if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
+               thread_add_timer(master, isis_run_dr,
+                                &circuit->level_arg[level - 1],
+                                2 * circuit->hello_interval[level - 1],
+                                &circuit->u.bc.t_run_dr[level - 1]);
+
+               thread_add_timer(master, send_hello_cb,
+                                &circuit->level_arg[level - 1],
+                                isis_jitter(circuit->hello_interval[level - 1],
+                                            IIH_JITTER),
+                                &circuit->u.bc.t_send_lan_hello[level - 1]);
+
+               circuit->u.bc.lan_neighs[level - 1] = list_new();
+       }
 }
 
 static void circuit_resign_level(struct isis_circuit *circuit, int level)
index 2f18b98d3f2d6c9ba9f8a7fd9c76c341a4593d90..a2367c9213b50546e4ff1ad23aa5d59b99bde70a 100644 (file)
@@ -1742,79 +1742,52 @@ int send_hello(struct isis_circuit *circuit, int level)
        return retval;
 }
 
-int send_lan_l1_hello(struct thread *thread)
+int send_hello_cb(struct thread *thread)
 {
-       struct isis_circuit *circuit;
-       int retval;
+       struct isis_circuit_arg *arg = THREAD_ARG(thread);
+       
+       assert(arg);
+       
+       struct isis_circuit *circuit = arg->circuit;
+       int level = arg->level;
 
-       circuit = THREAD_ARG(thread);
        assert(circuit);
-       circuit->u.bc.t_send_lan_hello[0] = NULL;
-
-       if (!(circuit->area->is_type & IS_LEVEL_1)) {
-               zlog_warn(
-                       "ISIS-Hello (%s): Trying to send L1 IIH in L2-only area",
-                       circuit->area->area_tag);
-               return 1;
-       }
 
-       if (circuit->u.bc.run_dr_elect[0])
-               isis_dr_elect(circuit, 1);
+       if (circuit->circ_type == CIRCUIT_T_P2P) {
+               circuit->u.p2p.t_send_p2p_hello = NULL;
 
-       retval = send_hello(circuit, 1);
-
-       /* set next timer thread */
-       thread_add_timer(master, send_lan_l1_hello, circuit,
-                        isis_jitter(circuit->hello_interval[0], IIH_JITTER),
-                        &circuit->u.bc.t_send_lan_hello[0]);
-
-       return retval;
-}
-
-int send_lan_l2_hello(struct thread *thread)
-{
-       struct isis_circuit *circuit;
-       int retval;
-
-       circuit = THREAD_ARG(thread);
-       assert(circuit);
-       circuit->u.bc.t_send_lan_hello[1] = NULL;
+               send_hello(circuit, 1);
 
-       if (!(circuit->area->is_type & IS_LEVEL_2)) {
-               zlog_warn("ISIS-Hello (%s): Trying to send L2 IIH in L1 area",
-                         circuit->area->area_tag);
-               return 1;
+               thread_add_timer(master, send_hello_cb, arg,
+                                isis_jitter(circuit->hello_interval[1], IIH_JITTER),
+                                &circuit->u.p2p.t_send_p2p_hello);
+               return ISIS_OK;
        }
 
-       if (circuit->u.bc.run_dr_elect[1])
-               isis_dr_elect(circuit, 2);
-
-       retval = send_hello(circuit, 2);
-
-       /* set next timer thread */
-       thread_add_timer(master, send_lan_l2_hello, circuit,
-                        isis_jitter(circuit->hello_interval[1], IIH_JITTER),
-                        &circuit->u.bc.t_send_lan_hello[1]);
-
-       return retval;
-}
+       if (circuit->circ_type != CIRCUIT_T_BROADCAST) {
+               zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d",
+                         circuit->area->area_tag, circuit->circ_type);
+               return ISIS_WARNING;
+       }
 
-int send_p2p_hello(struct thread *thread)
-{
-       struct isis_circuit *circuit;
+       circuit->u.bc.t_send_lan_hello[level - 1] = NULL;
+       if (!(circuit->is_type & level)) {
+               zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit",
+                         circuit->area->area_tag, level, 3 - level);
+               return ISIS_WARNING;
+       }
 
-       circuit = THREAD_ARG(thread);
-       assert(circuit);
-       circuit->u.p2p.t_send_p2p_hello = NULL;
+       if (circuit->u.bc.run_dr_elect[level - 1])
+               isis_dr_elect(circuit, level);
 
-       send_hello(circuit, 1);
+       int rv = send_hello(circuit, level);
 
        /* set next timer thread */
-       thread_add_timer(master, send_p2p_hello, circuit,
-                        isis_jitter(circuit->hello_interval[1], IIH_JITTER),
-                        &circuit->u.p2p.t_send_p2p_hello);
+       thread_add_timer(master, send_hello_cb, arg,
+                        isis_jitter(circuit->hello_interval[level - 1], IIH_JITTER),
+                        &circuit->u.bc.t_send_lan_hello[level - 1]);
 
-       return ISIS_OK;
+       return rv;
 }
 
 /*
index 3d2420eb036abf340f7459c8e93b2215fd5ad509..f1cd6d4c1b8cb8c700c85103d6b8863ccd712d72 100644 (file)
@@ -208,9 +208,7 @@ int isis_receive(struct thread *thread);
 /*
  * Sending functions
  */
-int send_lan_l1_hello(struct thread *thread);
-int send_lan_l2_hello(struct thread *thread);
-int send_p2p_hello(struct thread *thread);
+int send_hello_cb(struct thread *thread);
 int send_csnp(struct isis_circuit *circuit, int level);
 int send_l1_csnp(struct thread *thread);
 int send_l2_csnp(struct thread *thread);