Пример #1
0
VOID 
	WAN_RemoveRasLink (
		IN PKIP_NDIS_ADAPTER pAdapter,
		IN PNDIS_WAN_LINE_DOWN pWanLineDown
		)
{
	PKIP_RAS_LINK RasLink = NULL;
	PLIST_ENTRY ListEntry;
	
	DBGLOG(( LTrace, "Local MAC: %.2X%.2X%.2X%.2X%.2X%.2X Remote MAC: %.2X%.2X%.2X%.2X%.2X%.2X\n", 
				pWanLineDown->LocalAddress[0],
				pWanLineDown->LocalAddress[1],
				pWanLineDown->LocalAddress[2],
				pWanLineDown->LocalAddress[3],
				pWanLineDown->LocalAddress[4],
				pWanLineDown->LocalAddress[5],
				pWanLineDown->RemoteAddress[0],
				pWanLineDown->RemoteAddress[1],
				pWanLineDown->RemoteAddress[2],
				pWanLineDown->RemoteAddress[3],
				pWanLineDown->RemoteAddress[4],
				pWanLineDown->RemoteAddress[5]
				));

	KIP_LOCK_ADAPTER(pAdapter);

	for( ListEntry = pAdapter->RasLinkList.Flink;
		ListEntry != &pAdapter->RasLinkList;
		ListEntry = ListEntry->Flink )
	{
		RasLink = CONTAINING_RECORD(ListEntry,KIP_RAS_LINK,Interface.Link);
		if ( (RtlCompareMemory(RasLink->RemoteAddress, pWanLineDown->RemoteAddress, ETHARP_HWADDR_LEN) == ETHARP_HWADDR_LEN ) 
			&& (RtlCompareMemory(RasLink->Interface.CurrentMacAddress, pWanLineDown->LocalAddress, ETHARP_HWADDR_LEN) == ETHARP_HWADDR_LEN ) )
		{
			RemoveEntryList (&RasLink->Interface.Link);
			break;
		}
		RasLink = NULL;
	}
	KIP_UNLOCK_ADAPTER(pAdapter);

	if ( RasLink ){

		// update arp table
		etharp_remove_static_entry( &RasLink->IpAddr );
		etharp_remove_static_entry( &RasLink->RemoteIpAddr );

		ProtocolUnBindAdapter(
			RasLink->Interface.Miniport,
			&RasLink->Interface,
			&RasLink->Interface.Protocol
			);
		NdisFreeMemory ( RasLink, sizeof (KIP_RAS_LINK), 0 );		
	}
}
Пример #2
0
/*********************************************************************************************************
** 函数名称: __tshellArp
** 功能描述: 系统命令 "arp"
** 输 入  : iArgC         参数个数
**           ppcArgV       参数表
** 输 出  : 0
** 全局变量:
** 调用模块:
*********************************************************************************************************/
static INT  __tshellArp (INT  iArgC, PCHAR  *ppcArgV)
{
    if (iArgC < 2) {
        fprintf(stderr, "argments error!\n");
        return  (-ERROR_TSHELL_EPARAM);
    }
    
    if (lib_strcmp(ppcArgV[1], "-a") == 0) {                            /*  显示 arp 表                 */
        INT     iFd;
        CHAR    cBuffer[512];
        ssize_t sstNum;
        
        iFd = open("/proc/net/arp", O_RDONLY);
        if (iFd < 0) {
            fprintf(stderr, "can not open /proc/net/arp : %s\n", lib_strerror(errno));
            return  (PX_ERROR);
        }
        
        do {
            sstNum = read(iFd, cBuffer, sizeof(cBuffer));
            if (sstNum > 0) {
                write(STDOUT_FILENO, cBuffer, (size_t)sstNum);
            }
        } while (sstNum > 0);
        
        close(iFd);
        
        return  (ERROR_NONE);
    
    } else if (lib_strcmp(ppcArgV[1], "-s") == 0) {                     /*  加入一个静态转换关系        */
        INT             i;
        INT             iTemp[6];
        ip_addr_t       ipaddr;
        struct eth_addr ethaddr;
        err_t           err;
        
        if (iArgC != 4) {
            fprintf(stderr, "argments error!\n");
            return  (-ERROR_TSHELL_EPARAM);
        }
        
        ipaddr.addr = ipaddr_addr(ppcArgV[2]);
        if (ipaddr.addr == IPADDR_NONE) {
            fprintf(stderr, "bad inet address : %s\n", ppcArgV[2]);
            return  (-ERROR_TSHELL_EPARAM);
        }
        
        if (sscanf(ppcArgV[3], "%02x:%02x:%02x:%02x:%02x:%02x",
                   &iTemp[0], &iTemp[1], &iTemp[2], 
                   &iTemp[3], &iTemp[4], &iTemp[5]) != 6) {
            fprintf(stderr, "bad physical address : %s\n", ppcArgV[3]);
            return  (-ERROR_TSHELL_EPARAM);
        }
        
        for (i = 0; i < 6; i++) {
            ethaddr.addr[i] = (u8_t)iTemp[i];
        }
        
        LOCK_TCPIP_CORE();
        err = etharp_add_static_entry(&ipaddr, &ethaddr);
        UNLOCK_TCPIP_CORE();
        
        return  (err ? PX_ERROR : ERROR_NONE);
    
    } else if (lib_strcmp(ppcArgV[1], "-d") == 0) {                     /*  删除一个静态转换关系        */
        ip_addr_t       ipaddr;
        err_t           err;
        
        if (iArgC != 3) {                                               /*  删除全部转换关系            */
            struct netif *netif;
            
            LWIP_NETIF_LOCK();
            for (netif = netif_list; netif != LW_NULL; netif = netif->next) {
                if (netif->flags & NETIF_FLAG_ETHARP) {
                    netifapi_netif_common(netif, etharp_cleanup_netif, LW_NULL);
                }
            }
            LWIP_NETIF_UNLOCK();
            
            return  (ERROR_NONE);
        }
        
        ipaddr.addr = ipaddr_addr(ppcArgV[2]);
        if (ipaddr.addr == IPADDR_NONE) {
            fprintf(stderr, "bad inet address : %s\n", ppcArgV[2]);
            return  (-ERROR_TSHELL_EPARAM);
        }
        
        LOCK_TCPIP_CORE();
        err = etharp_remove_static_entry(&ipaddr);
        UNLOCK_TCPIP_CORE();
        
        return  (err ? PX_ERROR : ERROR_NONE);
    
    } else {
        fprintf(stderr, "argments error!\n");
        return  (-ERROR_TSHELL_EPARAM);
    }
}