/* * Method checks whether client is supported and assigned addresses from any class */ bool TSrvCfgMgr::isClntSupported(SPtr<TDUID> duid, SPtr<TIPv6Addr> clntAddr, int iface, SPtr<TSrvMsg> msg) { SPtr<TSrvCfgIface> ptrIface; firstIface(); while((ptrIface=getIface())&&(ptrIface->getID()!=iface)) ; /** @todo: reject-client and accept-only does not work in stateless mode */ if (this->stateless()) return true; int classCnt = 0; if (ptrIface) { SPtr<TSrvCfgAddrClass> ptrClass; ptrIface->firstAddrClass(); while(ptrClass=ptrIface->getAddrClass()) { if (ptrClass->clntSupported(duid,clntAddr,msg)) return true; classCnt++; } } if (!classCnt) { Log(Warning) << "There are no address class defined on the " << ptrIface->getFullName() << ". Maybe you are trying to configure clients on cascade relay interface? " << "If that is so, please define separate class on this interface, too." << LogEnd; } return false; }
bool TSrvCfgMgr::validateConfig() { SPtr<TSrvCfgIface> ptrIface; if (0 == (this->countIface() + this->inactiveIfacesCnt())) { Log(Crit) << "Config problem: No interface defined." << LogEnd; return false; } firstIface(); while(ptrIface=getIface()) { if (!this->validateIface(ptrIface)) return false; } return true; }
QString MachineBridge::getIfaceFormattedMac(int iface) { return getIfaceFormattedMac(getIface(iface)); }
/*This function will receive the packet and forward it accordingly*/ void receiveforwardpkt(int sockfd,int index,BridgeEntry* bridgetable[],int clients[],fd_set* allset) { int num; EtherPkt receivedpkt; ARP_PKT arppkt; IP_PKT ippkt; int type; int length; int forward_index; int counter; memset(&receivedpkt,'0',sizeof(receivedpkt)); memset(&arppkt,'0',sizeof(arppkt)); memset(&ippkt,'0',sizeof(ippkt)); fprintf(stderr,"Started reading the packet\n"); num=read(sockfd,&receivedpkt.dst,18); /*If any of the clients closed then do the cleaning operation*/ if (num==0) { fprintf(stderr,"Station or router closed"); clients[index]=-1; FD_CLR(sockfd,allset); return; } read(sockfd,&receivedpkt.src,18); fprintf(stderr,"Destination Mac:%s ,Source Mac:%s\n",receivedpkt.dst,receivedpkt.src); read(sockfd,(char *)&receivedpkt.type,sizeof(short)); read(sockfd,(char *)&receivedpkt.size,sizeof(short)); type=ntohs(receivedpkt.type); if (!presentInbridgeTable(bridgetable,receivedpkt.src)) { addTobridgeTable(bridgetable,receivedpkt.src,index); } displaytableinfo(bridgetable); if (type==TYPE_IP_PKT) { fprintf(stderr,"Ip packet received\n"); read(sockfd,(char *)&ippkt.dstip,sizeof(IPAddr)); read(sockfd,(char *)&ippkt.srcip,sizeof(IPAddr)); read(sockfd,(char *)&ippkt.protocol,sizeof(short)); read(sockfd,(char *)&ippkt.sequenceno,sizeof(unsigned long)); read(sockfd,(char *)&ippkt.length,sizeof(short)); length=ntohs(ippkt.length); memset(&ippkt.data,'\0',sizeof(ippkt.data)); read(sockfd,ippkt.data,length); } else if (type==TYPE_ARP_PKT) { fprintf(stderr,"ARP packet received\n"); read(sockfd,(char *)&arppkt.op,sizeof(short)); read(sockfd,(char *)&arppkt.srcip,sizeof(IPAddr)); read(sockfd,&arppkt.srcmac,18); read(sockfd,(char *)&arppkt.dstip,sizeof(IPAddr)); read(sockfd,&arppkt.dstmac,18); } else { fprintf(stderr,"Unknown type packet received.Something wrong with reading\n"); return; } fprintf(stderr,"Finished reading the packet\n"); forward_index=getIface(bridgetable,receivedpkt.dst); if (forward_index>-1) { forwardpacket(clients[forward_index],receivedpkt,ippkt,arppkt); } else { for(counter=0;counter<no_ports;counter++) { if (counter==index) { continue; } if (clients[counter]>=0) { forwardpacket(clients[counter],receivedpkt,ippkt,arppkt); } } } }
bool MachineBridge::setCableConnected(uint32_t iface, bool connected) { return setCableConnected(getIface(iface), connected); }
bool MachineBridge::setAttachmentData(uint32_t iface, uint32_t attachmentType, QString qAttachmentData) { return setAttachmentData(getIface(iface), attachmentType, qAttachmentData); }
bool MachineBridge::setIfaceMac(uint32_t iface, QString qMac) { return setIfaceMac(getIface(iface), qMac); }
bool MachineBridge::setIfaceAttachmentType(uint32_t iface, uint32_t attachmentType) { return setIfaceAttachmentType(getIface(iface), attachmentType); }
QString MachineBridge::getGenericDriver(uint32_t iface) { return getGenericDriver(getIface(iface)); }
bool MachineBridge::setIfaceEnabled(uint32_t iface, bool enabled) { return setIfaceEnabled(getIface(iface), enabled); }
QString MachineBridge::getHostIface(uint32_t iface) { return getHostIface(getIface(iface)); }
QString MachineBridge::getInternalName(uint32_t iface) { return getInternalName(getIface(iface)); }
QString MachineBridge::getNatNetwork(uint32_t iface) { return getNatNetwork(getIface(iface)); }
QString MachineBridge::getAttachmentData(uint32_t iface, uint32_t attachmentType) { return getAttachmentData(getIface(iface), getAttachmentType(getIface(iface))); }
bool TClntIfaceMgr::modifyPrefix(int iface, SPtr<TIPv6Addr> prefix, int prefixLen, unsigned int pref, unsigned int valid, PrefixModifyMode mode) { SPtr<TClntIfaceIface> ptrIface = (Ptr*)getIfaceByID(iface); if (!ptrIface) { Log(Error) << "Unable to find interface with ifindex=" << iface << ", prefix add/modify operation failed." << LogEnd; return false; } string action; int conf = 0; // number of successfully configured prefixes int status = -1; switch (mode) { case PREFIX_MODIFY_ADD: action = "Adding"; break; case PREFIX_MODIFY_UPDATE: action = "Updating"; break; case PREFIX_MODIFY_DEL: action = "Deleting"; break; } // option: split this prefix and add it to all interfaces Log(Notice) << "PD: " << action << " prefix " << prefix->getPlain() << "/" << (int)prefixLen << " to all interfaces (prefix will be split to /" << int(prefixLen+8) << " prefixes if necessary)." << LogEnd; if (prefixLen>120) { Log(Error) << "PD: Unable to perform prefix operation: prefix /" << prefixLen << " can't be split. At least /120 prefix is required." << LogEnd; return false; } // get a list of interfaces that we will assign prefixes to TIfaceIfaceLst ifaceLst; vector<string> ifaceNames = ClntCfgMgr().getDownlinkPrefixIfaces(); for (vector<string>::const_iterator name = ifaceNames.begin(); name != ifaceNames.end(); ++name) { SPtr<TIfaceIface> x = getIfaceByName(*name); if (x) ifaceLst.push_back(x); else Log(Warning) << "Interface " << *name << " specified in downlink-prefix-ifaces is missing." << LogEnd; } if (ifaceLst.size() == 0) { SPtr<TIfaceIface> x; firstIface(); while ( x = (Ptr*)getIface() ) { if (x->getID() == ptrIface->getID()) { Log(Debug) << "PD: Interface " << x->getFullName() << " is the interface, where prefix has been obtained, skipping." << LogEnd; continue; } // for each interface present in the system... if (!x->flagUp()) { Log(Debug) << "PD: Interface " << x->getFullName() << " is down, ignoring." << LogEnd; continue; } if (!x->flagRunning()) { Log(Debug) << "PD: Interface " << x->getFullName() << " has flag RUNNING not set, ignoring." << LogEnd; continue; } if (!x->flagMulticast()) { Log(Debug) << "PD: Interface " << x->getFullName() << " is not multicast capable, ignoring." << LogEnd; continue; } if ( !(x->getMacLen() > 5) ) { Log(Debug) << "PD: Interface " << x->getFullName() << " has MAC address length " << x->getMacLen() << " (6 or more required), ignoring." << LogEnd; continue; } x->firstLLAddress(); if (!x->getLLAddress()) { Log(Debug) << "PD: Interface " << x->getFullName() << " has no link-local address, ignoring. (Disconnected? Not associated? No-link?)" << LogEnd; continue; } ifaceLst.push_back(x); } } Log(Info) << "PD: Using " << ifaceLst.size() << " suitable interface(s):"; TIfaceIfaceLst::const_iterator i; for (TIfaceIfaceLst::const_iterator i=ifaceLst.begin(); i!=ifaceLst.end(); ++i) { Log(Cont) << (*i)->getName() << " "; } Log(Cont) << LogEnd; if (ifaceLst.size() == 0) { Log(Warning) << "Suitable interfaces not found. Delegated prefix not split." << LogEnd; return true; } for (TIfaceIfaceLst::const_iterator i=ifaceLst.begin(); i!=ifaceLst.end(); ++i) { char buf[16]; int subprefixLen; memmove(buf, prefix->getAddr(), 16); if (ifaceLst.size() == 1) { // just one interface - use delegated prefix as is subprefixLen = prefixLen; } else if (ifaceLst.size()<256) { subprefixLen = prefixLen + 8; int offset = prefixLen/8; if (prefixLen%8 == 0) { // that's easy, just put ID in the next octet buf[offset] = (*i)->getID(); } else { // here's fun uint16_t existing = readUint16(buf+offset); uint16_t bitmask = 0xff00; uint16_t infixmask = ((uint8_t)(*i)->getID()) << 8; bitmask = bitmask >> (prefixLen%8); infixmask = infixmask >> (prefixLen%8); // clear out if there is anything there, i.e. server assigned prefix // with garbage in host section existing = existing & (~bitmask); existing = existing | (bitmask & infixmask); writeUint16(buf+offset, existing); } } else {