273 lines
9.5 KiB
C
273 lines
9.5 KiB
C
/*
|
|
******************************************************************************
|
|
* INTERPEAK SOURCE FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmpls_procfs.c,v $ $Revision: 1.2 $
|
|
* $Source: /home/interpeak/CVSRoot/ipmpls/src/ipmpls_procfs.c,v $
|
|
* $Author: jonas $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Jonas Rendel <Jonas.Rendel@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
|
|
#if defined(IPMPLS) && defined(IP_PORT_LKM)
|
|
#include "ipmpls_config.h"
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
#include <ipcom.h>
|
|
|
|
#include "ipmpls.h"
|
|
#include "ipmpls_h.h"
|
|
#include "ipmpls_ipstack.h"
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 EXTERN PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 7 LOCAL PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 8 DATA
|
|
****************************************************************************
|
|
*/
|
|
|
|
IP_EXTERN Ipmpls_data *ipmpls;
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 9 STATIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 10 GLOBAL FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 11 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmpls_route_proc_info
|
|
*===========================================================================
|
|
* Description: Prints MPLS route info
|
|
*
|
|
* Parameters: buffer - pointer to print buffer
|
|
* start - current head of print buffer
|
|
* offset - offset in print buffer.
|
|
* length - length of print buffer.
|
|
*
|
|
* Returns: Number of bytes printed.
|
|
*/
|
|
IP_PUBLIC int
|
|
ipmpls_route_proc_info(char *buffer, char **start, Ip_u32 offset, int length, Ip_bool is_ilm)
|
|
{
|
|
Ipmpls_route *rt;
|
|
Ipmpls_route *tree;
|
|
Ipcom_netif *netif;
|
|
Ip_u16 vr = ipcom_get_user_vr();
|
|
char addr_buf[50];
|
|
int i = 0;
|
|
int type;
|
|
int len = 0;
|
|
Ip_u32 pos = 0;
|
|
Ip_u32 begin = 0;
|
|
|
|
tree = ipcom_hash_get(ipmpls->label_tables, &vr);
|
|
|
|
if (tree == IP_NULL)
|
|
goto out;
|
|
|
|
type = is_ilm ? IPMPLS_LABEL_TYPE_GEN : IPMPLS_LABEL_TYPE_KEY;
|
|
|
|
rt = (Ipmpls_route*)ipcom_route_first_entry(tree->head);
|
|
|
|
while (rt != IP_NULL)
|
|
{
|
|
if (type == (int)IPMPLS_KEY_GET_TYPE(rt->key))
|
|
{
|
|
len += ipcom_sprintf(buffer + len,
|
|
"%d:%d:%d %x",
|
|
type,
|
|
IPMPLS_KEY_GET_LABELSPACE(rt->key),
|
|
IPMPLS_KEY_GET_LABEL(rt->key),
|
|
rt->age);
|
|
if (is_ilm)
|
|
len += ipcom_sprintf(buffer + len,
|
|
" %s ",
|
|
IPMPLS_ILM_PROTO(rt) == 0 ? "ipv4" : "ipv6");
|
|
else
|
|
len += ipcom_sprintf(buffer + len,
|
|
" %d ",
|
|
IPMPLS_NHLFE_MTU(rt));
|
|
|
|
for (i = 0; rt->oplist && i < rt->oplist->num_opcodes; i++)
|
|
{
|
|
switch (rt->oplist->opcodes[i].opcode)
|
|
{
|
|
case IPMPLS_OP_POP:
|
|
len += ipcom_sprintf(buffer + len,"pop");
|
|
break;
|
|
case IPMPLS_OP_PEEK:
|
|
len += ipcom_sprintf(buffer + len,"peek");
|
|
break;
|
|
case IPMPLS_OP_DLV:
|
|
len += ipcom_sprintf(buffer + len,"dlv");
|
|
break;
|
|
case IPMPLS_OP_SET_RX:
|
|
{
|
|
netif = (Ipcom_netif *) ipcom_mpls_ioevent(IP_NULL,
|
|
IPMPLS_EIOXINDEXTONETIF,
|
|
(void *)rt->oplist->opcodes[i].data.set.ifindex,
|
|
IP_NULL,
|
|
IP_NULL);
|
|
|
|
len += ipcom_sprintf(buffer + len,"setrx");
|
|
|
|
if(netif)
|
|
len += ipcom_sprintf(buffer + len,",%s",netif->name);
|
|
}
|
|
break;
|
|
case IPMPLS_OP_SET_RTAB:
|
|
len += ipcom_sprintf(buffer + len,"setvr,%d", rt->oplist->opcodes[i].data.set.ifindex);
|
|
break;
|
|
case IPMPLS_OP_PUSH:
|
|
len += ipcom_sprintf(buffer + len,"push,%d", rt->oplist->opcodes[i].data.push.u.ml_gen);
|
|
break;
|
|
case IPMPLS_OP_FWD:
|
|
len += ipcom_sprintf(buffer + len,"fwd,%d:%d:%d",
|
|
IPMPLS_KEY_GET_TYPE(rt->oplist->opcodes[i].data.fwd),
|
|
IPMPLS_KEY_GET_LABELSPACE(rt->oplist->opcodes[i].data.fwd),
|
|
IPMPLS_KEY_GET_LABEL(rt->oplist->opcodes[i].data.fwd));
|
|
break;
|
|
case IPMPLS_OP_SET:
|
|
netif = (Ipcom_netif *) ipcom_mpls_ioevent(IP_NULL,
|
|
IPMPLS_EIOXINDEXTONETIF,
|
|
(void *)rt->oplist->opcodes[i].data.set.ifindex,
|
|
IP_NULL,
|
|
IP_NULL);
|
|
|
|
len += ipcom_sprintf(buffer + len,"set");
|
|
|
|
if (netif)
|
|
len += ipcom_sprintf(buffer + len,",%s",netif->name);
|
|
|
|
switch(rt->oplist->opcodes[i].data.set.sa->sa_family)
|
|
{
|
|
#ifdef IPCOM_USE_INET
|
|
case IP_AF_INET:
|
|
{
|
|
struct Ip_sockaddr_in *sin = (struct Ip_sockaddr_in*)rt->oplist->opcodes[i].data.set.sa;
|
|
|
|
(void)ipcom_inet_ntop(IP_AF_INET, &sin->sin_addr, addr_buf, sizeof(addr_buf));
|
|
len += ipcom_sprintf(buffer + len,",%s", addr_buf);
|
|
break;
|
|
}
|
|
|
|
#endif
|
|
#ifdef IPCOM_USE_INET6
|
|
case IP_AF_INET6:
|
|
{
|
|
struct Ip_sockaddr_in6 *sin6 = (struct Ip_sockaddr_in6*)rt->oplist->opcodes[i].data.set.sa;
|
|
|
|
(void)ipcom_inet_ntop(IP_AF_INET6, &sin6->sin6_addr, addr_buf, sizeof(addr_buf));
|
|
len += ipcom_sprintf(buffer + len,",%s", addr_buf);
|
|
break;
|
|
}
|
|
#endif
|
|
default:
|
|
len += ipcom_sprintf(buffer + len,",unknown");
|
|
break;
|
|
}
|
|
break;
|
|
case IPMPLS_OP_NOP:
|
|
len += ipcom_sprintf(buffer + len, "nop");
|
|
break;
|
|
|
|
}
|
|
|
|
len += ipcom_sprintf(buffer + len, ",");
|
|
}
|
|
|
|
len += ipcom_sprintf(buffer + len,"\n");
|
|
|
|
pos = begin + len;
|
|
if (pos < offset)
|
|
{
|
|
len = 0;
|
|
begin = pos;
|
|
}
|
|
|
|
if (pos > offset + length)
|
|
goto out;
|
|
}
|
|
|
|
rt = (Ipmpls_route*)ipcom_route_next_entry(&rt->hdr);
|
|
}
|
|
|
|
out:
|
|
|
|
*start = buffer + (offset - begin);
|
|
len -= (offset - begin);
|
|
if (len > length)
|
|
len = length;
|
|
if (len < 0)
|
|
len = 0;
|
|
|
|
return (len);
|
|
}
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 11 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
#else
|
|
int ipmpls_procfs_empty_file = 1;
|
|
#endif
|