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

Main IP address changed or main interface changed #72

Open
altaweelala1983 opened this issue May 29, 2019 · 2 comments
Open

Main IP address changed or main interface changed #72

altaweelala1983 opened this issue May 29, 2019 · 2 comments

Comments

@altaweelala1983
Copy link

jsoninfo plugin does not update the IP address in "lastHopIP" and "destinationIP" fileds. To solve this modify olsr_change_myself_tc function:

void
olsr_change_myself_tc(void)
{
if (tc_myself)
{

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	// Added by Ala
	struct ipaddr_str buf;
	struct olsr_if *tmp_if;

	bool mainIPCahnged = true;
	int numIPs=0;
	// Run trough all interfaces and count number of valid interfaces
	for (tmp_if = olsr_cnf->interfaces; tmp_if != NULL; tmp_if = tmp_if->next)
	{
		
		if(tmp_if->interf)
		{
			if(inet_ntoa(tmp_if->interf->int_addr.sin_addr) !=0 )
			{
				numIPs++;					
			}
		}
		else
		{
			OLSR_PRINTF(1, "Interface has no address\n");	
		}
	}


	if(numIPs == 0)
	{
		OLSR_PRINTF(1, "error no active interface\n");	
	}
	else if(numIPs == 1)		
		// Run trough all interfaces again and check if olsr_cnf->main_addr is still valid
		for (tmp_if = olsr_cnf->interfaces; tmp_if != NULL; tmp_if = tmp_if->next)
			if(tmp_if->interf)
			{
				if(inet_ntoa(tmp_if->interf->int_addr.sin_addr) !=0 )
				{
					if(strcmp(inet_ntoa(tmp_if->interf->int_addr.sin_addr), ip4_to_string(&buf, olsr_cnf->main_addr.v4))==0)
					{
						OLSR_PRINTF(1, "main IP still valid\n");
						mainIPCahnged = false;											
					}
					else // reset the new main ip address
					{
						OLSR_PRINTF(1, "reset olsr_cnf->main_addr to new IP \n");	
						olsr_cnf->main_addr.v4 = tmp_if->interf->int_addr.sin_addr;							
					}
				}
			}
			else
			{
				OLSR_PRINTF(1, "interface has no address\n");	
			}
	else if(numIPs == 2)		
	{
		// change here if you find some future bugs
		OLSR_PRINTF(1, "two active interfaces\n");	
	}
	
	if(mainIPCahnged)
	{
		OLSR_PRINTF(1, "modified olsr_cnf->main_addr:%s\n", ip4_to_string(&buf, olsr_cnf->main_addr.v4));		
	}

	// End by Ala
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	

	

 
	if (ipequal(&tc_myself->addr, &olsr_cnf->main_addr))
	{
		return;
	}

	/*
	* Flush our own tc_entry.
	*/

	olsr_delete_tc_entry(tc_myself);
}

/*
* The old entry for ourselves is gone, generate a new one and trigger SPF.
*/
tc_myself = olsr_add_tc_entry(&olsr_cnf->main_addr);
changes_topology = true;

}

@mathiashro
Copy link
Contributor

Hello @altaweelala1983, many thanks for reporting the issue. Since it's not fully clear to me what you had change - can you possibly create a patch or pull request so we can update the source here as well?

@mathiashro
Copy link
Contributor

Hi @altaweelala1983 , can you provide a pull request / patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants