Skip to content

Main IP address changed or main interface changed #72

@altaweelala1983

Description

@altaweelala1983

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;

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions