📄 pppend.c
字号:
struct ifnet * pIfnet; connectionId = pfwStackIdGet (pDrvCtrl->state->stackObj); pfwId = pfwIdGet (pDrvCtrl->state->pluginObj->pfwObj); unitNum = (pfwId - 1)* PPP_END_MAX_SESSIONS_PER_FRWK + connectionId; sprintf(ifName,"ppp%d",unitNum); /* Get the ifnet from the interface name */ if ((pIfnet = ifunit (ifName)) == NULL) return ERROR; return OK; }/********************************************************************************* pppEndSend -** NOMANUAL*/LOCAL STATUS pppEndSend ( void * pCookie, M_BLK_ID pMblk ) { PPP_DRV_CTRL *pDrvCtrl; END_OBJ *end; int retVal; PPP_END_STACK_DATA * pStackData; end = (END_OBJ *)pCookie; /* Get the pDrvCtrl structure from the END_OBJ */ pDrvCtrl = (PPP_DRV_CTRL *) end->devObject.pDevice; /* Get the stackData required for uniform implementation of RFC 2233 * counters */ pStackData = (PPP_END_STACK_DATA *)(pDrvCtrl->state)->stackData; if (pStackData->txBlocked == TRUE) { return (END_ERR_BLOCK); } /* update RFC 1213 counters */ pDrvCtrl->end.mib2Tbl.ifOutUcastPkts++; pDrvCtrl->end.mib2Tbl.ifOutOctets += pMblk->mBlkPktHdr.len; RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, pStackData->pfwRFC2233CountPair, M2_ctrId_ifOutUcastPkts, 1); RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, pStackData->pfwRFC2233CountPair, M2_ctrId_ifHCOutUcastPkts, 1); retVal = pfwSend (pDrvCtrl->state, pMblk); return (retVal); }/********************************************************************************* pppPacketDataGet -** NOMANUAL*/LOCAL STATUS pppPacketDataGet ( M_BLK_ID pMblk, LL_HDR_INFO *llHdrInfo ) { /* We will hardcode the packet type to 0x800 (IP) for now */ /* In PPP, the only llHdrInfo fields which are relevant are dataOffset and the packet type */ memset (llHdrInfo, 0, sizeof (LL_HDR_INFO)); llHdrInfo->pktType = 0x800; /* Offset the address, control and protocol field */ llHdrInfo->dataOffset = 2; return (OK); }/********************************************************************************* pppMCastAddrAdd -** NOMANUAL*/LOCAL STATUS pppMCastAddrAdd ( PPP_DRV_CTRL* pDrvCtrl, char* pAddress ) { return (OK); }/********************************************************************************* pppMCastAddrDel -** NOMANUAL*/LOCAL STATUS pppMCastAddrDel ( PPP_DRV_CTRL* pDrvCtrl, char* pAddress ) { return (OK); }/********************************************************************************* pppMCastAddrGet -** NOMANUAL*/LOCAL STATUS pppMCastAddrGet ( PPP_DRV_CTRL* pDrvCtrl, MULTI_TABLE* pTable ) { return (OK); }/********************************************************************************* endPPPAddressForm -** NOMANUAL*/LOCAL M_BLK_ID pppAddressForm ( M_BLK_ID pMblk, /* pointer to packet mBlk */ M_BLK_ID pSrcAddr, /* structure containing source address */#ifdef PPP_T2CP3_OR_BELOW_COMPATIBLE M_BLK_ID pDstAddr /* structure containing destination address */#else M_BLK_ID pDstAddr, /* structure containing destination address */ BOOL bcastFlag /* use link-level broadcast? */#endif /* PPP_T2CP3_OR_BELOW_COMPATIBLE */ ) { BYTE *cp; int protocol = 0x21; /* Add the PPP IP protocol to the header */ M_PREPEND (pMblk, 2, M_DONTWAIT); if (pMblk != NULL) { cp = mtod(pMblk, u_char *); *cp++ = protocol >> 8; *cp++ = protocol & 0xFF; } return (pMblk); }/********************************************************************************* pppIoctl -** NOMANUAL*/LOCAL int pppIoctl ( END_OBJ * pEnd, /* device receiving command */ int cmd, /* ioctl command code */ caddr_t data /* command argument */ ) { int error = OK; long value; UINT32 oldFlags; PPP_DRV_CTRL *pDrvCtrl = (PPP_DRV_CTRL *) pEnd->devObject.pDevice; PPP_END_STACK_DATA *stackData = (PPP_END_STACK_DATA *)pDrvCtrl->state->stackData; struct ifaddr *ifa = (struct ifaddr *)data; /* Get the pDrvCtrl structure from the END_OBJ */ if (pfwPluginObjStateLock (pDrvCtrl->state) != OK) return ERROR; switch ((UINT)cmd) { case EIOCGFLAGS: *(int *)data = pEnd->flags; break; case EIOCSFLAGS: oldFlags = pEnd->flags; value = (long) data; if (value < 0) { value = -value; value--; END_FLAGS_CLR (pEnd, value); } else END_FLAGS_SET (pEnd, value); /* check if interface state has been toggled */ if ((oldFlags ^ pEnd->flags) & IFF_UP) {#ifdef PPP_DEBUG printf ("END Flags Changed: old 0x%lx, new 0x%lx: stack 0x%x\n", (long unsigned int) oldFlags,pEnd->flags,(UINT32) pDrvCtrl->state->stackObj);#endif /* PPP_DEBUG */ if (stackData->administrativeInterfaceControl == TRUE) { if (pEnd->flags & IFF_UP) { /* raise Interface is UP event */#ifdef PPP_DEBUG printf ("PPP_END: Interface up: stack 0x%x\n", (UINT32) pDrvCtrl->state->stackObj);#endif /* PPP_DEBUG */ pfwEventRaise(pDrvCtrl->state->stackObj, stackData->interfaceUpEvent,0); } else { /* raise Interface is DOWN event */#ifdef PPP_DEBUG printf ("PPP_END: Interface Down: stack 0x%x\n", (UINT32) pDrvCtrl->state->stackObj);#endif /* PPP_DEBUG */ pfwEventRaise(pDrvCtrl->state->stackObj, stackData->interfaceDownEvent,0); } } stackData->administrativeInterfaceControl = TRUE; } break; case EIOCGHDRLEN: if (data == NULL) error = EINVAL; else { *(int *)data = 48; } break; case EIOCGMIB2: if (data == NULL) { error = EINVAL; } else bcopy((char *)&pEnd->mib2Tbl, (char *)data, sizeof(pEnd->mib2Tbl)); break;#if 0 case EIOCQUERY: if (pppNptDriver == FALSE) { error = EINVAL; } else { END_QUERY *pEndQuery = (END_QUERY *)data; if (pEndQuery->query == END_BIND_QUERY && pEndQuery->queryLen >= 4) { *(FUNCPTR *)pEndQuery->queryData = (FUNCPTR)pppBind; pEndQuery->queryLen = sizeof(FUNCPTR); } else error = EINVAL; } break;#endif case SIOCSIFDSTADDR: if (ifa->ifa_dstaddr->sa_family != AF_INET) error = EAFNOSUPPORT; break;#ifdef PPP_END_RFC2233_CAPABLE case EIOCGMIB2233: if ((data == NULL) || (pEnd->pMib2Tbl == NULL)) { error = EINVAL; } else { *((M2_ID **)data) = pEnd->pMib2Tbl; } break;#endif /* PPP_END_RFC2233_CAPABLE */ default: error = EINVAL; break; } pfwPluginObjStateRelease(pDrvCtrl->state); return (error); }/********************************************************************************* pppBind -** NOMANUAL*/LOCAL STATUS pppBind ( PPP_DRV_CTRL * pDrvCtrl, void * pNetSvcInfo, /* reference to data from network service */ void * drvInfo, /* reference to buffer for driver info */ long type /* who's calling */ ) { return OK; }/********************************************************************************* receiveIf -** NOMANUAL*/LOCAL STATUS receiveIf ( PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID *packet ) { int retVal; END_OBJ *end; char *src, *dst; M_BLK_ID mBlk = *packet; M_BLK_ID newMblk; NET_POOL_ID netPoolId; unsigned int bufferSize; int requiredLeadingSpace; PPP_END_STACK_DATA *stackData = (PPP_END_STACK_DATA *)state->stackData; /* Get the END_OBJ from the state */ end = &(stackData->pDrvCtrl->end); src = mBlk->mBlkHdr.mData; bufferSize = mBlk->mBlkHdr.mLen; /* Is start of IP packet 4-byte aligned? */ if ((requiredLeadingSpace = ((int)src + 2) & 0x3) != 0) { if (M_LEADINGSPACE(mBlk) >= requiredLeadingSpace) { dst = (char *) (((int)src) - requiredLeadingSpace); bcopy (src, dst, bufferSize); mBlk->mBlkHdr.mData = dst; } else { netPoolId = pfwNetPoolIdGet (state->pluginObj->pfwObj); if ((newMblk = netTupleGet (netPoolId, bufferSize + 2, M_DONTWAIT,MT_DATA,TRUE)) == NULL) { netMblkClChainFree(mBlk); /* update RFC1213 counters */ end->mib2Tbl.ifInDiscards++; RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInDiscards, 1); return (ERROR); } dst = newMblk->mBlkHdr.mData; newMblk->mBlkHdr = mBlk->mBlkHdr; newMblk->mBlkPktHdr = mBlk->mBlkPktHdr; newMblk->mBlkHdr.mData = dst; newMblk->mBlkHdr.mData += 2; bcopy (mBlk->mBlkHdr.mData, newMblk->mBlkHdr.mData, bufferSize); netMblkClFree(mBlk); mBlk = newMblk; } } if (mBlk->mBlkHdr.mNext == NULL) mBlk->mBlkPktHdr.len = mBlk->mBlkHdr.mLen; mBlk->mBlkHdr.mFlags |= M_PKTHDR; /* update RFC1213 counters */ end->mib2Tbl.ifInUcastPkts++; end->mib2Tbl.ifInOctets += mBlk->mBlkPktHdr.len; RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInUcastPkts, 1); RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifHCInUcastPkts, 1); retVal = netJobAdd ((FUNCPTR)end->receiveRtn, (int)end, (int)mBlk, 0, 0, 0); #if 0 retVal = (*end->receiveRtn) ((void *)end, mBlk); #endif return (retVal); }/********************************************************************************* pppEndComponentCreate - initialize and add PPP end component to framework** This routine creates the END plug-in object and adds to the PPP framework. ** RETURNS: OK or ERROR*/STATUS pppEndComponentCreate ( PFW_OBJ *pfw ) { PPP_END_COMPONENT *pEndComponent; PFW_PLUGIN_OBJ *endPluginObj; pEndComponent = (PPP_END_COMPONENT *) pfwMalloc (pfw, sizeof (PPP_END_COMPONENT)); if (pEndComponent == NULL) { printf ("pppEndInit - Unable to allocate memory of size %d \ byte s\n", (int) sizeof (PFW_COMPONENT_OBJ)); return (ERROR); } bzero((char *)pEndComponent, sizeof (PPP_END_COMPONENT)); endPluginObj = (PFW_PLUGIN_OBJ *)&(pEndComponent->component); pEndComponent->component.protocol = 0; pEndComponent->component.layerObj = pfwLayerObjGet (pfw, "INTERFACE_LAYER"); strcpy (endPluginObj->name, "PPP_END"); endPluginObj->pfwObj = pfw; endPluginObj->profileDataSize = 0; endPluginObj->stackDataSize = sizeof (PPP_END_STACK_DATA); endPluginObj->profileDataConstruct = NULL; endPluginObj->profileDataDestruct = NULL; endPluginObj->profileDataCopy = NULL; endPluginObj->stackDataConstruct = pppEndStackDataConstruct; endPluginObj->stackDataDestruct = NULL; endPluginObj->receive = receiveIf; endPluginObj->send = sendIf; endPluginObj->stackAdd = stackAdd; endPluginObj->stackDelete = stackDelete; endPluginObj->interfaceBind = endInterfaceBind; if (pfwComponentAdd (&pEndComponent->component) == ERROR) { printf ("pppEndInit - END Driver could not be added to the \ framework\n"); return (ERROR); } /* * publish PPP_INTERFACE_UP and PPP_INTERFACE_DOWN events that are raised * in response to administrative interface UP and DOWN events */ if (pfwEventPublish(pfw,"PPP_INTERFACE_UP_EVENT") == NULL) { return ERROR; } if (pfwEventPublish(pfw,"PPP_INTERFACE_DOWN_EVENT") == NULL) { return ERROR; } /* This event allows us to send END_ERR_BLOCKED status if we are swamped */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -