23 LinkTable *lt1, PacketStore *ps1, StatsModule *sm1)
24 : maxIface(maxIface1), portNum(portNum1), ift(ift1),
25 lt(lt1),
ps(ps1), sm(sm1) {
26 nRdy = 0; maxSockNum = -1;
28 sock =
new int[maxIface+1];
29 for (
int i = 0; i <= maxIface; i++) sock[i] = -1;
33 IoProcessor::~IoProcessor() {
49 cerr <<
"IoProcessor::setup: socket call failed\n";
57 cerr <<
"IoProcessor::setup: bind call failed for ("
59 <<
", " <<
portNum <<
") check interface's IP "
60 <<
"address and port\n";
72 bool IoProcessor::setupBootSock(ipa_t bootIp, ipa_t nmIp1) {
77 cerr <<
"IoProcessor::setupBootSock: socket call failed\n";
82 cerr <<
"IoProcessor::setupBootIp: bind call failed, "
83 <<
"check boot IP address\n";
89 void IoProcessor::closeBootSock() {
94 pktx IoProcessor::receive() {
99 if (px == 0) {
return 0; }
101 buffer_t& b = *p.buffer;
103 ipa_t sIpAdr; ipp_t sPort;
106 p.bufferLen = nbytes;
108 if (errno == EAGAIN) {
111 fatal(
"IoProcessor::receive: error in recvfrom call");
126 if (!p.hdrErrCheck()) {
ps->
free(px);
return 0; }
127 p.tunIp = sIpAdr; p.tunPort = sPort;
137 struct timeval zero; zero.tv_sec = zero.tv_usec = 0;
141 (fd_set *)NULL, (fd_set *)NULL, &zero);
142 }
while (
nRdy < 0 && cnt++ < 10);
144 cerr <<
"IoProcessor::receive: select failed "
145 << cnt-1 <<
" times\n";
148 fatal(
"IoProcessor::receive: select failed");
150 if (
nRdy == 0)
return 0;
166 cerr <<
"IoProcessor:receive: out of packets\n";
170 buffer_t& b = *p.buffer;
172 ipa_t sIpAdr; ipp_t sPort;
175 if (nbytes < 0) fatal(
"IoProcessor::receive: error in recvfrom call");
189 if (!p.hdrErrCheck()) {
ps->
free(px);
return 0; }
193 uint64_t nonce = ntohl(p.payload()[2]); nonce <<= 32;
194 nonce |= ntohl(p.payload()[3]);
197 if (lnk == 0 || cIf !=
lt->getIface(lnk)) {
199 cerr <<
"IoProcessor::receive: bad packet: lnk=" << lnk <<
" "
206 p.inLink = lnk; p.bufferLen = nbytes;
207 p.tunIp = sIpAdr; p.tunPort = sPort;
214 void IoProcessor::send(pktx px,
int lnk) {
230 (
void *) p.buffer, p.length,
232 }
while (rv == -1 && errno == EAGAIN && lim++ < 10);
234 fatal(
"IoProcessor:: send: failure in sendto");
239 ipa_t farIp =
lt->getPeerIpAdr(lnk);
240 ipp_t farPort =
lt->getPeerPort(lnk);
241 if (farIp == 0 || farPort == 0) {
ps->
free(px);
return; }
256 (
void *) p.buffer, p.length,
258 }
while (rv == -1 && errno == EAGAIN && lim++ < 10);
260 cerr <<
"IoProcessor:: send: failure in sendto (errno="