📄 rip2.c
字号:
/* sprintf(debug_string, "Before"); */
strcpy(debug_string, "Before");
ATI_DEBUG_PRINT(debug_string);
/* sprintf(debug_string,
" -----------------------------------"
"--------------------------------\n\r"); */
strcpy(debug_string,
" -----------------------------------"
"--------------------------------\n\r");
ATI_DEBUG_PRINT(debug_string);
#endif
/* ignore RIP-2 packets if RIP1_ONLY is on */
if( node->r2_recvmode == RECV_RIP1 && rh->version == 2 )
{
/* see RFC 1058, section 3.4 and RFC 1723 3.6 and 4.1 */
return(0); /* do not do version 2 routes */
}
if( node->r2_recvmode == RECV_RIP2 && rh->version == 1 )
{
/* see RFC 1058, section 3.4 and RFC 1723 3.6 and 4.1 */
return(0); /* do not do version 2 routes */
}
/* Neither RIP-1 or 2 version packet */
if( rh->version != 1 && rh->version != 2 )
{
return(0); /* only understand version 1 and 2. */
}
ep = (RIP2_ENTRY *)&rpkt->af_id;
if( rh->version == 1 )
{
/* If doing version 1 packets then if the submask or nethop field */
/* is non-zero then do not do any of the packet. */
/* (see RFC 1058, section 3.4) */
for( i = 0; i < pkt_cnt; i++ )
{
if( memcmp(ep->submask, "\0\0\0\0", 4) != 0 ||
memcmp(ep->nexthop, "\0\0\0\0", 4) != 0 )
{
#if (NU_DEBUG_RIP2 == NU_TRUE)
/* sprintf(debug_string, "Cannot do rip2 packets.\n\r"); */
strcpy(debug_string, "Cannot do rip2 packets.\n\r");
ATI_DEBUG_PRINT(debug_string);
/* sprintf(debug_string, "submask = %d.%d.%d.%d\n\rnexthop = %d.%d.%d.%d\n\r",
ep->submask[0],
ep->submask[1],
ep->submask[2],
ep->submask[3],
ep->nexthop[0],
ep->nexthop[1],
ep->nexthop[2],
ep->nexthop[3]); */
strcpy(debug_string, "submask = ");
NU_ITOA(ep->submask[0], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->submask[1], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->submask[2], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->submask[3], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, "\n\rnexthop = ");
NU_ITOA(ep->nexthop[0], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->nexthop[1], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->nexthop[2], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->nexthop[3], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, "\n\r");
ATI_DEBUG_PRINT(debug_string);
#endif
return(0);
}
ep++;
}
}
ep = (RIP2_ENTRY *)&rpkt->af_id;
#if (NU_DEBUG_RIP2 == NU_TRUE)
/* sprintf(debug_string, "RIP Version: %d\n\r", rh->version); */
strcat(debug_string, "RIP Version: ");
NU_ITOA(rh->version, temp, 10);
strcat(debug_string, temp);
strcat(debug_string, "\n\r");
ATI_DEBUG_PRINT(debug_string);
#endif
for( i = 0; i < pkt_cnt; i++ )
{
/* if af_id is 0xFFFF then it is an auth type entry. */
if( ep->af_id == RIP2_FFFF )
{
/* if pw is null then user did not want to use authentication */
if( pw == (RIP2_AUTH *)NULL )
{
ep++;
continue; /* ignore RIP2 authentication packets */
}
n.rt_auth->af_id = ep->af_id;
n.rt_auth->authtype = INTSWAP(ep->routetag);
memcpy(n.rt_auth->auth, ep->ip_addr, 16);
/* if the authentication does not match, then do not do */
/* any of this packet. */
if( n.rt_auth->authtype != pw->authtype ||
memcmp(n.rt_auth->auth, pw->auth, sizeof(pw->auth)) != 0 )
return(0);
ep++;
continue;
}
else
n.rt_auth = 0;
/* If address is zero then don't do it, this means that they are */
/* wanting to update the default route for this network. */
if( memcmp(ep->ip_addr, "\0\0\0\0", 4) == 0 )
{
#if (NU_DEBUG_RIP2 == NU_TRUE)
/* sprintf(debug_string, "Would update the default route.\n\r"); */
strcpy(debug_string, "Would update the default route.\n\r");
ATI_DEBUG_PRINT(debug_string);
/* sprintf(debug_string, "Address: %d.%d.%d.%d -- %d.%d.%d.%d -- %d\n\r",
ep->ip_addr[0],
ep->ip_addr[1],
ep->ip_addr[2],
ep->ip_addr[3],
ep->submask[0],
ep->submask[1],
ep->submask[2],
ep->submask[3],
LONGSWAP(ep->metric)); */
strcpy(debug_string, "Address: ");
NU_ITOA(ep->ip_addr[0], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->ip_addr[1], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->ip_addr[2], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->ip_addr[3], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, " -- ");
NU_ITOA(ep->submask[0], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->submask[1], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->submask[2], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(ep->submask[3], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, " -- ");
NU_ITOA(LONGSWAP(ep->metric), temp, 10);
strcat(debug_string, temp);
strcat(debug_string, "\n\r");
ATI_DEBUG_PRINT(debug_string);
#endif
continue;
}
/* route entry found */
n.rt_rip2->af_id = ep->af_id;
n.rt_rip2->routetag = INTSWAP(ep->routetag);
memcpy( n.rt_rip2->ip_addr, ep->ip_addr, 4);
if( rh->version == 2 )
memcpy( n.rt_rip2->submask, ep->submask, 4);
else
memcpy( n.rt_rip2->submask, default_mask, 4);
memcpy( n.rt_rip2->nexthop, ep->nexthop, 4);
memcpy( (char *)&(n.rt_gateway.sck_addr), ep->nexthop, 4);
/* Add interface metric to route metric */
n.rt_rip2->metric = LONGSWAP(ep->metric);
n.rt_rip2->metric += node->r2_device->dev_metric;
#if (NU_DEBUG_RIP2 == NU_TRUE)
/* sprintf(debug_string, "Address: %d.%d.%d.%d -- %d.%d.%d.%d -- %d\n\r",
n.rt_rip2->ip_addr[0],
n.rt_rip2->ip_addr[1],
n.rt_rip2->ip_addr[2],
n.rt_rip2->ip_addr[3],
n.rt_rip2->submask[0],
n.rt_rip2->submask[1],
n.rt_rip2->submask[2],
n.rt_rip2->submask[3],
n.rt_rip2->metric); */
strcpy(debug_string, "Address: ");
NU_ITOA(n.rt_rip2->ip_addr[0], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(n.rt_rip2->ip_addr[1], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(n.rt_rip2->ip_addr[2], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(n.rt_rip2->ip_addr[3], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, " -- ");
NU_ITOA(n.rt_rip2->submask[0], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(n.rt_rip2->submask[1], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(n.rt_rip2->submask[2], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, ".");
NU_ITOA(n.rt_rip2->submask[3], temp, 10);
strcat(debug_string, temp);
strcat(debug_string, " -- ");
NU_ITOA(n.rt_rip2->metric, temp, 10);
strcat(debug_string, temp);
strcat(debug_string, "\n\r");
ATI_DEBUG_PRINT(debug_string);
#endif
/* Cannot be greater than RT_INFINITY. (see RFC 2453) */
if (n.rt_rip2->metric > RT_INFINITY )
n.rt_rip2->metric = RT_INFINITY;
n.rt_device = node->r2_device;
/* See if it is a class A, B or C address */
c = RIP2_IsNetworkClass_ABC(ep->ip_addr);
b = RIP2_IsBroadcast_Address(ep->ip_addr, c);
/* do not update routes that have a metric of infinity and */
/* is not a class A, B or C address or is a broadcast address */
if( LONGSWAP(ep->metric) < (UINT32)RT_INFINITY && c != 0 && b == 0)
{
/* Mark the route as UP. */
n.rt_flags = (RT_UP);
ret = RTAB_Insert_Node(&n);
if( ret == -1 )
return(-1);
}
ep++;
}
#if (NU_DEBUG_RIP2 == NU_TRUE)
/* sprintf(debug_string,
" -----------------------------------"
"--------------------------------\n\r"); */
strcpy(debug_string,
" -----------------------------------"
"--------------------------------\n\r");
ATI_DEBUG_PRINT(debug_string);
/* sprintf(debug_string, "After "); */
strcpy(debug_string, "After ");
ATI_DEBUG_PRINT(debug_string);
#endif
return(0);
} /* RIP2_Update_Table */
/*************************************************************************
*
* FUNCTION
*
* RIP2_IsNetworkClass_ABC
*
* DESCRIPTION
*
* If IP address is A, B or C return true.
* A class A address, the 32 bit is off.
* A class B address, the 32 bit is on and 31 bit is off.
* A class C address, the 32 bit is on and 31 bit is on.
*
* INPUTS
*
* *ip_addr
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -