diff options
| author | Christian Franke <chris@opensourcerouting.org> | 2018-10-10 11:16:39 +0200 | 
|---|---|---|
| committer | Christian Franke <chris@opensourcerouting.org> | 2018-12-04 12:49:25 +0100 | 
| commit | 7c4f7aabc5866238584dfd9497ec6cef32311ca1 (patch) | |
| tree | 23e5bd786dee59dfda8dbeaa4010e18ae55808b0 | |
| parent | 7da4aa3c7a8a4e4726bf06d08e2fd67175244211 (diff) | |
isisd: reduce code duplication for levels
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
| -rw-r--r-- | isisd/isis_circuit.c | 36 | ||||
| -rw-r--r-- | isisd/isis_dr.c | 77 | ||||
| -rw-r--r-- | isisd/isis_dr.h | 3 | ||||
| -rw-r--r-- | isisd/isis_events.c | 47 | ||||
| -rw-r--r-- | isisd/isis_pdu.c | 91 | ||||
| -rw-r--r-- | isisd/isis_pdu.h | 4 | 
6 files changed, 92 insertions, 166 deletions
diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 4c095c26d1..20094fb623 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -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 */ diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c index f71fe9555b..b2ec8ae594 100644 --- a/isisd/isis_dr.c +++ b/isisd/isis_dr.c @@ -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), diff --git a/isisd/isis_dr.h b/isisd/isis_dr.h index ed26558b08..5cab985d4b 100644 --- a/isisd/isis_dr.h +++ b/isisd/isis_dr.h @@ -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); diff --git a/isisd/isis_events.c b/isisd/isis_events.c index 9f58c24b71..db197c7bea 100644 --- a/isisd/isis_events.c +++ b/isisd/isis_events.c @@ -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) diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index 2f18b98d3f..a2367c9213 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -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;  }  /* diff --git a/isisd/isis_pdu.h b/isisd/isis_pdu.h index 3d2420eb03..f1cd6d4c1b 100644 --- a/isisd/isis_pdu.h +++ b/isisd/isis_pdu.h @@ -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);  | 
