📄 pmrpc_srp.c
字号:
/************************************************************************
* Copyright (C) 2004 Combrio Networks Co. *
* This unpublished source code is the property of Nexware Corporation.*
* All rights reserved. Use, duplication, or disclosure are restricted *
* and subject to the authorization from Combrio Networks Corporation. *
************************************************************************/
/************************************************************************
* File name: pmrpcsrp.c *
* *
* Description: Fulfill functions of server rpc application interface *
* *
************************************************************************/
#include <stdio.h>
#include <string.h>
#include "pmrpc_srp.h"
#include "include/pm_api.h"
static UI32_T DropTcpAck = 0;
static UI32_T TcpAckLen = 52;
static int cam_last_addr=0x3FFF;
static int cam_static_range=0x3c00;
static int cam_reserve_range=39;
int drop_tcpack(tcpdrop_args *tcp_drop)
{
int i;
if(tcp_drop->action!=0 && tcp_drop->action!=1)
return -1;
if(tcp_drop->action)//drop
{
if(tcp_drop->droplen > cam_reserve_range+43)
tcp_drop->droplen = cam_reserve_range+43;
for(i=44;i<=tcp_drop->droplen;i++)
if(addDropTcpAckFilter(i)!=0)
return -1;
}
else
{
if(tcp_drop->droplen > cam_reserve_range+43)
tcp_drop->droplen = cam_reserve_range+43;
for(i=44;i<=tcp_drop->droplen;i++)
if(delDropTcpAckFilter(i-43,1)!=0)
return -1;
}
DropTcpAck=tcp_drop->action;
TcpAckLen=tcp_drop->droplen;
return 0;
}
int delDropTcpAckFilter(int length, int region)
{
struct board_info_t pmp0_board;
struct rule_del rule;
rule.addr=length;
rule.region=region;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
if(del_filter_entry(pmp0_board,&rule)!=0)
return -1;
return 0;
}
int addDropTcpAckFilter(int length)
{
struct board_info_t pmp0_board;
sPM_FILTER_ENTRY *new_entry;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
new_entry = get_filter_entry();
new_entry->type=1;
new_entry->len.inuse=1;
new_entry->len.data=length-4;
new_entry->len.mask=0xFFFF;
new_entry->flag.inuse=1;
new_entry->flag.data=0x10;
new_entry->flag.mask=0xFF;
new_entry->action.memData.portNum=9;
new_entry->cam_addr=length-43;
if( add_filter_entry(pmp0_board, new_entry) != 0 )
return -1;
return 0;
}
int set_crc(int mode)
{
struct board_info_t pmp0_board;
int ret;
struct config_value entry;
memset(&entry,0,sizeof(struct config_value));
entry.type=PM_SET_5381_FCS_LENGTH;
entry.value=mode;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
ret=write_config_value(pmp0_board,PMC5381_CHIP,&entry);
if(ret != 0)
return -1;
return 0;
}
int set_scramble ( int mode )
{
struct board_info_t pmp0_board;
int ret;
struct config_value entry;
memset(&entry,0,sizeof(struct config_value));
entry.type=PM_SET_5381_PACKET_SCRAMBLE;
entry.value=mode;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
ret=write_config_value(pmp0_board,PMC5381_CHIP,&entry);
if(ret != 0)
return -1;
return 0;
}
int set_minlen(unsigned int len)
{
struct board_info_t pmp0_board;
int ret;
struct config_value entry;
memset(&entry,0,sizeof(struct config_value));
entry.type=PM_SET_5381_MAXIMUM_LEN;
entry.value=len;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
ret=write_config_value(pmp0_board,PMC5381_CHIP,&entry);
if(ret != 0)
return -1;
return 0;
}
int set_maxlen (unsigned int len)
{
struct board_info_t pmp0_board;
int ret;
struct config_value entry;
memset(&entry,0,sizeof(struct config_value));
entry.type=PM_SET_5381_MINIMUM_LEN;
entry.value=len;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
ret=write_config_value(pmp0_board,PMC5381_CHIP,&entry);
if(ret != 0)
return -1;
return 0;
}
int set_mactable ( int mode )
{
struct board_info_t pmp0_board;
int ret;
struct config_value entry;
memset(&entry,0,sizeof(struct config_value));
entry.type=PM_SET_TPM_MACTABLE;
entry.value=mode;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
ret=write_config_value(pmp0_board,PM_CHIP,&entry);
if(ret==!0)
return -1;
return 0;
}
int set_def_rule(defrule_args *args )
{
struct board_info_t pmp0_board;
UI16_T port_map;
// UI32_T LAST_CAMADDR=0x3FF;
struct sPM_access_fltr data;
if(args->action!=0 && args->action!=1)
return -1;
memset(&data,0,sizeof(struct sPM_access_fltr));
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
if(read_def_rule(pmp0_board,&data)!=0)
return -1;
if(args->action==0) //drop
{
data.dropFlag=1;
data.forwardFlag=0;
data.learnFlag=0;
data.groupId=0;
if(write_def_rule(pmp0_board, &data)!=0)
return -1;
}
else if(args->action==1) //forward
{
data.dropFlag=0;
data.forwardFlag=1;
data.learnFlag=0;
data.groupId=0;
if(write_def_rule(pmp0_board, &data)!=0)
return -1;
if(set_def_portmap(pmp0_board,&(args->port_map))!=0)
return -1;
}
else
;
return 0;
}
config_struct* show_config (void)
{
struct board_info_t pmp0_board;
static config_struct ret_result;
int dropmode,i;
unsigned int portmap;
UI32_T macmode;
struct pmc5381_config new_info;
struct sPM_access_fltr data;
struct rpm_config rpmcfg;
struct tpm_config tpmcfg;
memset(&ret_result,0,sizeof(config_struct));
ret_result.tcp_drop.droplen=TcpAckLen;
ret_result.tcp_drop.action=DropTcpAck;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
read_def_rule(pmp0_board,&data);
get_def_portmap(pmp0_board,&portmap);
if(data.dropFlag)
ret_result.def_rule.action=0;
else
ret_result.def_rule.action=1;
ret_result.def_rule.port_map=portmap;
get_pmc5381_config(pmp0_board,&new_info);
ret_result.crc_mode=new_info.fcs_type;
ret_result.scramble_mode=new_info.scramble;
get_rpm_config(pmp0_board,&rpmcfg);
ret_result.maxlen=rpmcfg.long_limit;
ret_result.minlen=rpmcfg.short_limit;
get_tpm_config(pmp0_board,&tpmcfg);
ret_result.mactb_mode=tpmcfg.mac_en;
return &ret_result;
}
extern int cam_static_range;
extern int cam_reserve_range;
int configure_rule(rule_struct *index_filter)
{
struct board_info_t pmp0_board;
sPM_FILTER_ENTRY *new_entry,*previous;
UI8_T region=1; //1:persistent region 0: filter region
UI32_T cam_addr;
struct sPM_access_fltr data;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
if (index_filter->index<1 || index_filter->index>=(cam_static_range-cam_reserve_range))
return -1;
new_entry = get_filter_entry();
new_entry->action.fltrData.portMap=index_filter->port_map;
new_entry->cam_addr=index_filter->index+cam_reserve_range;
if(index_filter->pt == 0)
{
new_entry->pt.inuse=0;
}
else
{
new_entry->pt.inuse=1;
new_entry->pt.data = index_filter->pt;
if(index_filter->pt_mask==0)
new_entry->pt.mask=0xFF;
else
new_entry->pt.mask=index_filter->pt_mask;
}
if (index_filter->dp == 0)
{
new_entry->dp.inuse=0;
}
else
{
new_entry->dp.inuse=1;
new_entry->dp.data=index_filter->dp;
if(index_filter->dp_mask==0)
new_entry->dp.mask=0xFFFF;
else new_entry->dp.mask=index_filter->dp_mask;
}
if (index_filter->sp == 0)
{
new_entry->sp.inuse=0;
}
else
{
new_entry->sp.inuse=1;
new_entry->sp.data=index_filter->sp;
if(index_filter->sp_mask==0)
new_entry->sp.mask=0xFFFF;
else
new_entry->sp.mask=index_filter->sp_mask;
}
if(index_filter->dip==0)
{
new_entry->dip.inuse = 0;
}
else
{
new_entry->dip.inuse = 1;
new_entry->dip.data = index_filter->dip;
if(index_filter->dip_mask==0)
new_entry->dip.mask=0xFFFFFFFF;
else
new_entry->dip.mask=index_filter->dip_mask;
}
if(index_filter->sip==0)
{
new_entry->sip.inuse = 0;
}
else
{
new_entry->sip.inuse = 1;
new_entry->sip.data = index_filter->sip;
if(index_filter->sip_mask==0)
new_entry->sip.mask=0xFFFFFFFF;
else
new_entry->sip.mask=index_filter->sip_mask;
}
new_entry->type=region;
if(index_filter->flowid!=0)
{
if( filterEntryListAdd_flowid(new_entry,index_filter)!=0 )
return -1;
}
else
{
if( add_filter_entry(pmp0_board,new_entry)!=0)
return -1;
}
return 0;
}
int filterEntryListAdd_flowid(sPM_FILTER_ENTRY *new_entry,rule_struct *index_filter)
{
struct board_info_t pmp0_board;
struct flowid_mac flowid;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
flowid.index=index_filter->index;
flowid.flowid=index_filter->flowid;
flowid.mac.index=index_filter->mac_index;
flowid.mac.cookie=index_filter->cookie;
if(add_filter_entry(pmp0_board,new_entry)!=0)
return -1;
if(set_pkm_flowid(pmp0_board,&flowid)!=0)
return -1;
return 0;
}
//
extern sPM_FILTER_ENTRY *filter_entry_pos[];
rule_struct* show_rule(unsigned int index)
{
struct board_info_t pmp0_board;
static rule_struct ret_result;
sPM_FILTER_ENTRY *temp_entry;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
// if(index < 0 || index >= (cam_static_range-cam_reserve_range))
// return -1;
temp_entry->cam_addr=index;
memset(&ret_result,0,sizeof(rule_struct));
show_filter_entry(pmp0_board,temp_entry);
ret_result.index=index;
if (temp_entry->dip.inuse)
{
ret_result.dip=temp_entry->dip.data;
ret_result.dip_mask=temp_entry->dip.mask;
}
if (temp_entry->sip.inuse)
{
ret_result.sip=temp_entry->sip.data;
ret_result.sip_mask=temp_entry->sip.mask;
}
if (temp_entry->dp.inuse)
{
ret_result.dp=temp_entry->dp.data;
ret_result.dp_mask=temp_entry->dp.mask;
}
if (temp_entry->sp.inuse)
{
ret_result.sp=temp_entry->sp.data;
ret_result.sp_mask=temp_entry->sp.mask;
}
if (temp_entry->pt.inuse)
{
ret_result.pt=temp_entry->pt.data;
ret_result.pt_mask=temp_entry->pt.mask;
}
ret_result.port_map=temp_entry->action.fltrData.portMap;
ret_result.flowid=temp_entry->action.memData.flowID;
ret_result.cookie=temp_entry->action.memData.mac.cookie;
ret_result.mac_index=temp_entry->action.memData.mac.index;
ret_result.drop=temp_entry->action.fltrData.dropFlag;
return &ret_result;
}
int clear_rule(unsigned int index)
{
struct board_info_t pmp0_board;
struct rule_del rule;
int region=1;
pmp0_board.type=PMP_BOARD_ID;
pmp0_board.num=0;
if (index < 0 || index >= (cam_static_range-cam_reserve_range))
return -1;
if (index == 0)
{
if(del_all_filter_entry(pmp0_board,®ion)!=0)
return -1;
return 0;
}
rule.addr=index;
rule.region=region;
if(del_filter_entry(pmp0_board,&rule)!=0)
return -1;
return 0;
}
int config_batch_rule(rule_array_struct* arg)
{
int i;
for(i=0;i<PKT_NUM;i++)
{
configure_rule(&((*arg).rule_array[i]));
}
return 0;
}
int load_batch_rule(rule_array_struct* arg)
{
int i;
for(i=0;i<PKT_NUM;i++)
{
configure_rule(&((*arg).rule_array[i]));
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -