~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to proxy/ICP.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include "BaseManager.h"
47
47
#include "HdrUtils.h"
48
48
 
49
 
#if defined (_WIN32)
50
 
extern long glShutdownInProgress;
51
 
#endif
52
 
 
53
49
extern CacheLookupHttpConfig global_cache_lookup_config;
54
50
HTTPHdr gclient_request;
55
51
 
336
332
    PeerReadDataAllocator.free(this->_state);
337
333
  }
338
334
  if (_cache_req_hdr_heap_handle) {
339
 
    xfree(_cache_req_hdr_heap_handle);
 
335
    ats_free(_cache_req_hdr_heap_handle);
340
336
    _cache_req_hdr_heap_handle = NULL;
341
337
  }
342
338
  if (_cache_resp_hdr_heap_handle) {
343
 
    xfree(_cache_resp_hdr_heap_handle);
 
339
    ats_free(_cache_resp_hdr_heap_handle);
344
340
    _cache_resp_hdr_heap_handle = NULL;
345
341
  }
346
342
}
399
395
int
400
396
ICPPeerReadCont::StaleCheck(int event, Event * e)
401
397
{
 
398
  ip_port_text_buffer ipb;
402
399
  NOWARN_UNUSED(e);
403
400
  ink_release_assert(mutex->thread_holding == this_ethread());
404
401
 
405
 
  Debug("icp-stale", "Stale check res=%d for id=%d, [%s] from [%s:%d]",
 
402
  Debug("icp-stale", "Stale check res=%d for id=%d, [%s] from [%s]",
406
403
        event, _state->_rICPmsg->h.requestno,
407
 
        _state->_rICPmsg->un.query.URL, inet_ntoa(_state->_sender.sin_addr), ntohs(_state->_sender.sin_port));
 
404
    _state->_rICPmsg->un.query.URL, ats_ip_nptop(&_state->_sender, ipb, sizeof(ipb)));
408
405
 
409
406
  switch (event) {
410
407
  case ICP_STALE_OBJECT:
433
430
int
434
431
ICPPeerReadCont::ICPPeerQueryEvent(int event, Event * e)
435
432
{
 
433
  ip_port_text_buffer ipb;
436
434
  NOWARN_UNUSED(e);
437
 
  Debug("icp", "Remote Query lookup res=%d for id=%d, [%s] from [%s:%d]",
 
435
  Debug("icp", "Remote Query lookup res=%d for id=%d, [%s] from [%s]",
438
436
        event, _state->_rICPmsg->h.requestno,
439
 
        _state->_rICPmsg->un.query.URL, inet_ntoa(_state->_sender.sin_addr), ntohs(_state->_sender.sin_port));
 
437
    _state->_rICPmsg->un.query.URL, ats_ip_nptop(&_state->_sender, ipb, sizeof(ipb)));
440
438
  if (pluginFreshnessCalcFunc) {
441
439
    switch (event) {
442
440
    case CACHE_EVENT_OPEN_READ:
465
463
int
466
464
ICPPeerReadCont::ICPPeerQueryCont(int event, Event * e)
467
465
{
 
466
  ip_port_text_buffer ipb;
468
467
  NOWARN_UNUSED(event);
469
468
  NOWARN_UNUSED(e);
470
469
 
476
475
  _state->_cachelookupURL.create(NULL);
477
476
  const char *qurl = (const char *) _state->_rICPmsg->un.query.URL;
478
477
  _state->_cachelookupURL.parse(qurl, strlen(qurl));
479
 
  Debug("icp", "Remote Query for id=%d, [%s] from [%s:%d]",
 
478
  Debug("icp", "Remote Query for id=%d, [%s] from [%s]",
480
479
        _state->_rICPmsg->h.requestno,
481
 
        _state->_rICPmsg->un.query.URL, inet_ntoa(_state->_sender.sin_addr), ntohs(_state->_sender.sin_port));
 
480
        _state->_rICPmsg->un.query.URL,
 
481
    ats_ip_nptop(&_state->_sender, ipb, sizeof(ipb))
 
482
  );
482
483
 
483
484
  SET_HANDLER((ICPPeerReadContHandler) & ICPPeerReadCont::ICPPeerQueryEvent);
484
485
  if (_state->_rICPmsg->un.query.URL && *_state->_rICPmsg->un.query.URL) {
530
531
ICPPeerReadCont::PeerReadStateMachine(PeerReadData * s, Event * e)
531
532
{
532
533
  AutoReference l(&_recursion_depth);
 
534
  ip_port_text_buffer ipb; // scratch buffer for diagnostic messages.
533
535
  //-----------------------------------------------------------
534
536
  // State machine to process ICP data received on UDP socket
535
537
  //-----------------------------------------------------------
571
573
          return EVENT_DONE;
572
574
        }
573
575
      }
574
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
576
#if !defined(__GNUC__)
575
577
    _end_case_read_active:     // fix DEC warnings
576
578
#endif
577
579
      ink_release_assert(0);    // Should never happen
594
596
        ink_assert(s->_peer->readAction == NULL);
595
597
        Action *a = s->_peer->RecvFrom_re(this, this, buf,
596
598
                                          buf->write_avail() - 1,
597
 
                                          (struct sockaddr *)
598
 
                                          &s->_peer->fromaddr,
 
599
                                          &s->_peer->fromaddr.sa,
599
600
                                          &s->_peer->fromaddrlen);
600
601
        if (!a) {
601
602
          a = ACTION_IO_ERROR;
624
625
          return EVENT_DONE;
625
626
        }
626
627
      }
627
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
628
#if !defined(__GNUC__)
628
629
    _end_case_read_data:       // fix DEC warnings
629
630
#endif
630
631
      ink_release_assert(0);    // Should never happen
653
654
          break;
654
655
        }
655
656
      }
656
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
657
#if !defined(__GNUC__)
657
658
    _end_case_read_data_done:  // fix DEC warnings
658
659
#endif
659
660
      ink_release_assert(0);    // Should never happen
688
689
        }
689
690
        // Validate receiver and convert the received sockaddr
690
691
        //   to internal sockaddr format.
691
 
        struct sockaddr_in from;
692
 
        if (!s->_peer->ExtToIntRecvSockAddr(&s->_peer->fromaddr, &from)) {
 
692
        IpEndpoint from;
 
693
        if (!s->_peer->ExtToIntRecvSockAddr(&s->_peer->fromaddr.sa, &from.sa)) {
693
694
          int status;
694
695
          ICPConfigData *cfg = _ICPpr->GetConfig()->globalConfig();
695
696
          ICPMsg_t *ICPmsg = (ICPMsg_t *) buf;
717
718
 
718
719
            int icp_reply_port = cfg->ICPDefaultReplyPort();
719
720
            if (!icp_reply_port) {
720
 
              icp_reply_port = ntohs(s->_peer->fromaddr.sin_port);
 
721
              icp_reply_port = ntohs(ats_ip_port_cast(&s->_peer->fromaddr));
721
722
            }
722
 
            PeerConfigData *Pcfg = NEW(new PeerConfigData(PeerConfigData::CTYPE_SIBLING,
723
 
                                                          &s->_peer->fromaddr.sin_addr, 0,
724
 
                                                          icp_reply_port));
 
723
            PeerConfigData *Pcfg = NEW(new PeerConfigData(
 
724
                PeerConfigData::CTYPE_SIBLING,
 
725
                IpAddr(s->_peer->fromaddr),
 
726
                0,
 
727
                icp_reply_port
 
728
            ));
725
729
            ParentSiblingPeer *P = NEW(new ParentSiblingPeer(PEER_SIBLING, Pcfg, _ICPpr, true));
726
730
            status = _ICPpr->AddPeer(P);
727
731
            ink_release_assert(status);
728
732
            status = _ICPpr->AddPeerToSendList(P);
729
733
            ink_release_assert(status);
730
734
 
731
 
            P->GetChan()->setRemote(P->GetIP()->s_addr, P->GetPort());
 
735
            P->GetChan()->setRemote(P->GetIP());
732
736
 
733
737
            // coverity[uninit_use_in_call]
734
 
            Note("ICP Peer added ip=%u.%u.%u.%u port=%d", PRINT_IP(P->GetIP()->s_addr), P->GetPort());
 
738
            Note("ICP Peer added ip=%s", ats_ip_nptop(P->GetIP(), ipb, sizeof(ipb)));
735
739
            from = s->_peer->fromaddr;
736
740
          } else {
737
741
          invalid_message:
739
743
            // Sender does not exist in ICP configuration, terminate
740
744
            //
741
745
            ICP_INCREMENT_DYN_STAT(invalid_sender_stat);
742
 
            Debug("icp", "Received msg from invalid sender [%s:%d]",
743
 
                  inet_ntoa(s->_peer->fromaddr.sin_addr), ntohs(s->_peer->fromaddr.sin_port));
 
746
            Debug("icp", "Received msg from invalid sender [%s]",
 
747
              ats_ip_nptop(&s->_peer->fromaddr, ipb, sizeof(ipb)));
744
748
 
745
749
            s->_peer->buf = NULL;
746
750
            s->_next_state = READ_NOT_ACTIVE;
762
766
        if ((s->_rICPmsg->h.version != ICP_VERSION_2)
763
767
            && (s->_rICPmsg->h.version != ICP_VERSION_3)) {
764
768
          ICP_INCREMENT_DYN_STAT(read_not_v2_icp_stat);
765
 
          Debug("icp", "Received (v=%d) !v2 && !v3 msg from sender [%s:%d]",
766
 
                (uint32_t) s->_rICPmsg->h.version, inet_ntoa(from.sin_addr), ntohs(from.sin_port));
 
769
          Debug("icp", "Received (v=%d) !v2 && !v3 msg from sender [%s]",
 
770
            (uint32_t) s->_rICPmsg->h.version, ats_ip_nptop(&from, ipb, sizeof(ipb)));
767
771
 
768
772
          s->_rICPmsg = NULL;
769
773
          s->_buf = NULL;
788
792
          }
789
793
        } else {
790
794
          // We have a response message for an ICP query.
791
 
          Debug("icp", "Response for Id=%d, from [%s:%d]",
792
 
                s->_rICPmsg->h.requestno, inet_ntoa(s->_sender.sin_addr), ntohs(s->_sender.sin_port));
 
795
          Debug("icp", "Response for Id=%d, from [%s]",
 
796
            s->_rICPmsg->h.requestno, ats_ip_nptop(&s->_sender, ipb, sizeof(ipb)));
793
797
          ICP_INCREMENT_DYN_STAT(icp_remote_responses_stat);
794
798
          s->_next_state = GET_ICP_REQUEST;
795
799
          RECORD_ICP_STATE_CHANGE(s, 0, GET_ICP_REQUEST);
796
800
          break;                // move to next_state
797
801
        }
798
802
      }
799
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
803
#if !defined(__GNUC__)
800
804
    _end_case_process_data_read:       // fix DEC warnings
801
805
#endif
802
806
      ink_release_assert(0);    // Should never happen
809
813
 
810
814
        if (s->_queryResult == CACHE_EVENT_LOOKUP) {
811
815
          // Use the received ICP data buffer for the response message
812
 
          Debug("icp", "Sending ICP_OP_HIT for id=%d, [%s] to [%s:%d]",
813
 
                s->_rICPmsg->h.requestno, data, inet_ntoa(s->_sender.sin_addr), ntohs(s->_sender.sin_port));
 
816
          Debug("icp", "Sending ICP_OP_HIT for id=%d, [%.*s] to [%s]",
 
817
            s->_rICPmsg->h.requestno, datalen, (const char *)data, ats_ip_nptop(&s->_sender, ipb, sizeof(ipb)));
814
818
          ICP_INCREMENT_DYN_STAT(icp_cache_lookup_success_stat);
815
819
          status = ICPRequestCont::BuildICPMsg(ICP_OP_HIT,
816
820
                                               s->_rICPmsg->h.requestno, 0 /* optflags */ , 0 /* optdata */ ,
818
822
                                               data, datalen, &s->_mhdr, s->_iov, s->_rICPmsg);
819
823
        } else if (s->_queryResult == CACHE_EVENT_LOOKUP_FAILED) {
820
824
          // Use the received ICP data buffer for response message
821
 
          Debug("icp", "Sending ICP_OP_MISS for id=%d, [%s] to [%s:%d]",
822
 
                s->_rICPmsg->h.requestno, data, inet_ntoa(s->_sender.sin_addr), ntohs(s->_sender.sin_port));
 
825
          Debug("icp", "Sending ICP_OP_MISS for id=%d, [%.*s] to [%s]",
 
826
            s->_rICPmsg->h.requestno, datalen, (const char *)data, ats_ip_nptop(&s->_sender, ipb, sizeof(ipb)));
823
827
          ICP_INCREMENT_DYN_STAT(icp_cache_lookup_fail_stat);
824
828
          status = ICPRequestCont::BuildICPMsg(ICP_OP_MISS,
825
829
                                               s->_rICPmsg->h.requestno, 0 /* optflags */ , 0 /* optdata */ ,
845
849
          break;
846
850
        }
847
851
      }
848
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
852
#if !defined(__GNUC__)
849
853
    _end_case_awaiting_cache_lookup_response:  // fix DEC warnings
850
854
#endif
851
855
      ink_release_assert(0);    // Should never happen
860
864
        RECORD_ICP_STATE_CHANGE(s, 0, WRITE_DONE);
861
865
        ink_assert(s->_peer->writeAction == NULL);
862
866
        Action *a = s->_peer->SendMsg_re(this, this,
863
 
                                         &s->_mhdr, &s->_sender);
 
867
                                         &s->_mhdr, &s->_sender.sa);
864
868
        if (!a) {
865
869
          a = ACTION_IO_ERROR;
866
870
        }
872
876
        } else if (a == ACTION_IO_ERROR) {
873
877
          // Partial write.
874
878
          ICP_INCREMENT_DYN_STAT(query_response_partial_write_stat);
875
 
          unsigned char x[4];
876
 
          *(uint32_t *) & x = (uint32_t) s->_sender.sin_addr.s_addr;
877
879
          // coverity[uninit_use_in_call]
878
 
          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%d.%d.%d.%d",
879
 
                ntohs(s->_rICPmsg->h.msglen), -1, x[0], x[1], x[2], x[3]);
 
880
          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%s",
 
881
            ntohs(s->_rICPmsg->h.msglen), -1, ats_ip_ntop(&s->_sender, ipb, sizeof(ipb)));
880
882
          s->_next_state = READ_NOT_ACTIVE;
881
883
          RECORD_ICP_STATE_CHANGE(s, 0, READ_NOT_ACTIVE);
882
884
          break;
885
887
          return EVENT_DONE;
886
888
        }
887
889
      }
888
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
890
#if !defined(__GNUC__)
889
891
    _end_case_send_reply:      // fix DEC warnings
890
892
#endif
891
893
      ink_release_assert(0);    // Should never happen
897
899
 
898
900
        if (len == (int)ntohs(s->_rICPmsg->h.msglen)) {
899
901
          ICP_INCREMENT_DYN_STAT(query_response_write_stat);
900
 
          s->_peer->LogSendMsg(s->_rICPmsg, &s->_sender);       // log query reply
 
902
          s->_peer->LogSendMsg(s->_rICPmsg, &s->_sender.sa);       // log query reply
901
903
        } else {
902
904
          // Partial write.
903
905
          ICP_INCREMENT_DYN_STAT(query_response_partial_write_stat);
904
 
          unsigned char x[4];
905
 
          *(uint32_t *) & x = (uint32_t) s->_sender.sin_addr.s_addr;
906
906
          // coverity[uninit_use_in_call]
907
 
          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%d.%d.%d.%d",
908
 
                ntohs(s->_rICPmsg->h.msglen), len, x[0], x[1], x[2], x[3]);
 
907
          Debug("icp_warn", "ICP response send, sent=%d res=%d, ip=%s",
 
908
            ntohs(s->_rICPmsg->h.msglen), len, ats_ip_ntop(&s->_sender, ipb, sizeof(ipb)));
909
909
        }
910
910
        // Processing complete, perform completion actions
911
911
        s->_next_state = READ_NOT_ACTIVE;
918
918
          break;                // move to next_state
919
919
        }
920
920
      }
921
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
921
#if !defined(__GNUC__)
922
922
    _end_case_write_done:      // fix DEC warnings
923
923
#endif
924
924
      ink_release_assert(0);    // Should never happen
941
941
        //
942
942
        Debug("icp", "No ICP Request for Id=%d", s->_rICPmsg->h.requestno);
943
943
        ICP_INCREMENT_DYN_STAT(no_icp_request_for_response_stat);
944
 
        Peer *p = _ICPpr->FindPeer(&s->_sender.sin_addr,
945
 
                                   ntohs(s->_sender.sin_port));
 
944
        Peer *p = _ICPpr->FindPeer(s->_sender);
946
945
        p->LogRecvMsg(s->_rICPmsg, 0);
947
946
        s->_next_state = READ_NOT_ACTIVE;
948
947
        RECORD_ICP_STATE_CHANGE(s, 0, READ_NOT_ACTIVE);
949
948
        break;                  // move to next_state
950
949
      }
951
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
950
#if !defined(__GNUC__)
952
951
    _end_case_get_icp_request: // fix DEC warnings
953
952
#endif
954
953
      ink_release_assert(0);    // Should never happen
975
974
          return EVENT_CONT;
976
975
        }
977
976
        // Log as "response for ICP request"
978
 
        Peer *p = _ICPpr->FindPeer(&s->_sender.sin_addr,
979
 
                                   ntohs(s->_sender.sin_port));
 
977
        Peer *p = _ICPpr->FindPeer(s->_sender);
980
978
        p->LogRecvMsg(s->_rICPmsg, 1);
981
979
 
982
980
        // Process the ICP response for the given ICP request
1005
1003
        s->_next_state = READ_NOT_ACTIVE;
1006
1004
        break;                  // move to next_state
1007
1005
      }
1008
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1006
#if !defined(__GNUC__)
1009
1007
    _end_case_get_icp_request_mutex:   // fix DEC warnings
1010
1008
#endif
1011
1009
      ink_release_assert(0);    // Should never happen
1034
1032
          break;                // restart
1035
1033
        }
1036
1034
      }
1037
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1035
#if !defined(__GNUC__)
1038
1036
    _end_case_read_not_active: // fix DEC warnings
1039
1037
#endif
1040
1038
      ink_release_assert(0);    // Should never happen
1087
1085
 
1088
1086
  if (_ICPmsg.h.opcode == ICP_OP_QUERY) {
1089
1087
    if (_ICPmsg.un.query.URL) {
1090
 
      xfree(_ICPmsg.un.query.URL);
 
1088
      ats_free(_ICPmsg.un.query.URL);
1091
1089
    }
1092
1090
  }
1093
1091
  if (pendingActions) {
1181
1179
        break;
1182
1180
      }
1183
1181
    }
1184
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1182
#if !defined(__GNUC__)
1185
1183
  _end_case:                   // fix DEC warnings
1186
1184
#endif
1187
1185
    ink_release_assert(0);      // should never happen
1210
1208
  // ICP message processing state machine
1211
1209
  //*******************************************
1212
1210
  ICPConfiguration *ICPcf = _ICPpr->GetConfig();
 
1211
  ip_port_text_buffer ipb;
1213
1212
 
1214
1213
  while (1) {                   // loop forever
1215
1214
 
1271
1270
          break;                // move to next_state
1272
1271
        }
1273
1272
      }
1274
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1273
#if !defined(__GNUC__)
1275
1274
    _end_case_icp_start:       // fix DEC warnings
1276
1275
#endif
1277
1276
      ink_release_assert(0);    // should never happen
1292
1291
        _next_state = ICP_DONE;
1293
1292
        return EVENT_DONE;
1294
1293
      }
1295
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1294
#if !defined(__GNUC__)
1296
1295
    _end_case_icp_off_terminate:       // fix DEC warnings
1297
1296
#endif
1298
1297
      ink_release_assert(0);    // should never happen
1322
1321
          int was_expected = P->ExpectedReplies(&_expected_replies_list);
1323
1322
          _expected_replies += was_expected;
1324
1323
          npending_actions++;
1325
 
          Action *a = P->SendMsg_re(this,
1326
 
                                    P,
1327
 
                                    &_sendMsgHdr, (struct sockaddr_in *) 0);
 
1324
          Action *a = P->SendMsg_re(this, P, &_sendMsgHdr, NULL);
1328
1325
          if (!a) {
1329
1326
            a = ACTION_IO_ERROR;
1330
1327
          }
1335
1332
              }
1336
1333
              (*pendingActions) (npending_actions) = a;
1337
1334
            }
1338
 
            P->LogSendMsg(&_ICPmsg, (struct sockaddr_in *) 0);  // log as send query
1339
 
            Debug("icp", "[ICP_QUEUE_REQUEST] Id=%d send query to [%s:%d]",
1340
 
                  _sequence_number, inet_ntoa(*P->GetIP()), P->GetPort());
 
1335
            P->LogSendMsg(&_ICPmsg, NULL);  // log as send query
 
1336
            Debug("icp", "[ICP_QUEUE_REQUEST] Id=%d send query to [%s]",
 
1337
              _sequence_number, ats_ip_nptop(P->GetIP(), ipb, sizeof(ipb)));
1341
1338
          } else {
1342
1339
            _expected_replies_list.ClearBit(P->GetPeerID());
1343
1340
            _expected_replies -= was_expected;
1344
1341
            // Partial or failed write.
1345
1342
            ICP_INCREMENT_DYN_STAT(send_query_partial_write_stat);
1346
 
            unsigned char x[4];
1347
 
            *(uint32_t *) & x = (uint32_t) (*P->GetIP()).s_addr;
1348
1343
            // coverity[uninit_use_in_call]
1349
1344
            Debug("icp_warn",
1350
 
                  "ICP query send, res=%d, ip=%d.%d.%d.%d", ntohs(_ICPmsg.h.msglen), x[0], x[1], x[2], x[3]);
 
1345
                  "ICP query send, res=%d, ip=%s", ntohs(_ICPmsg.h.msglen),
 
1346
              ats_ip_ntop(P->GetIP(), ipb, sizeof(ipb)));
1351
1347
          }
1352
1348
          SendPeers--;
1353
1349
        }
1372
1368
        _next_state = ICP_AWAITING_RESPONSE;
1373
1369
        return EVENT_DONE;
1374
1370
      }
1375
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1371
#if !defined(__GNUC__)
1376
1372
    _end_case_icp_queue_request:       // fix DEC warnings
1377
1373
#endif
1378
1374
      ink_release_assert(0);    // should never happen
1404
1400
          return EVENT_DONE;
1405
1401
        }
1406
1402
      }
1407
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1403
#if !defined(__GNUC__)
1408
1404
    _end_case_icp_awaiting_response:   // fix DEC warnings
1409
1405
#endif
1410
1406
      ink_release_assert(0);    // should never happen
1419
1415
        _next_state = ICP_POST_COMPLETION;
1420
1416
        break;                  // move to next_state
1421
1417
      }
1422
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1418
#if !defined(__GNUC__)
1423
1419
    _end_case_icp_dequeue_request:     // fix DEC warnings
1424
1420
#endif
1425
1421
      ink_release_assert(0);    // should never happen
1441
1437
        _next_state = ICP_WAIT_SEND_COMPLETE;
1442
1438
        break;                  // move to next_state
1443
1439
      }
1444
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1440
#if !defined(__GNUC__)
1445
1441
    _end_case_icp_post_completion:     // fix DEC warnings
1446
1442
#endif
1447
1443
      ink_release_assert(0);    // should never happen
1457
1453
        }
1458
1454
      }
1459
1455
      break;
1460
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1456
#if !defined(__GNUC__)
1461
1457
    _end_case_icp_wait_send_complete:  // fix DEC warnings
1462
1458
#endif
1463
1459
      ink_release_assert(0);    // should never happen
1475
1471
        _next_state = ICP_DONE;
1476
1472
        return EVENT_DONE;
1477
1473
      }
1478
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
1474
#if !defined(__GNUC__)
1479
1475
    _end_case_icp_request_not_active:  // fix DEC warnings
1480
1476
#endif
1481
1477
      ink_release_assert(0);    // should never happen
1493
1489
ICPRequestCont::ICPResponseMessage(int event, ICPMsg_t * m, int ICPMsg_len, Peer * peer)
1494
1490
{
1495
1491
  NOWARN_UNUSED(ICPMsg_len);
 
1492
  ip_port_text_buffer ipb, ipb2;
1496
1493
  if (event == EVENT_INTERVAL) {
 
1494
 
1497
1495
    _timeout = 0;
1498
1496
    remove_all_pendingActions();
1499
1497
 
1509
1507
          pp = _ICPpr->GetNthParentPeer(0, _ICPpr->GetStartingParentPeerBias());
1510
1508
          if (pp && !_expected_replies_list.IsBitSet(pp->GetPeerID())
1511
1509
              && pp->isUp()) {
1512
 
            _ret_sockaddr.sin_addr.s_addr = (pp->GetIP())->s_addr;
1513
 
            _ret_sockaddr.sin_port = htons(((ParentSiblingPeer *) pp)->GetProxyPort());
 
1510
            ats_ip_copy(&_ret_sockaddr.sa, pp->GetIP());
 
1511
            _ret_sockaddr.port() = htons(static_cast<ParentSiblingPeer*>(pp)->GetProxyPort());
1514
1512
            _ret_status = ICP_LOOKUP_FOUND;
1515
1513
 
1516
1514
            Debug("icp",
1517
 
                  "ICP timeout using parent Id=%d from [%s:%d] return [%s:%d]",
1518
 
                  _sequence_number, inet_ntoa(*pp->GetIP()),
1519
 
                  pp->GetPort(), inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
 
1515
              "ICP timeout using parent Id=%d from [%s] return [%s]",
 
1516
              _sequence_number,
 
1517
              ats_ip_nptop(pp->GetIP(), ipb, sizeof(ipb)),
 
1518
              ats_ip_nptop(&_ret_sockaddr, ipb2, sizeof(ipb2))
 
1519
            );
1520
1520
            return EVENT_DONE;
1521
1521
          }
1522
1522
        }
1542
1542
 
1543
1543
        ICP_INCREMENT_DYN_STAT(icp_query_hits_stat);
1544
1544
        ++_received_replies;
1545
 
        _ret_sockaddr.sin_addr.s_addr = (peer->GetIP())->s_addr;
1546
 
        _ret_sockaddr.sin_port = htons(((ParentSiblingPeer *) peer)->GetProxyPort());
 
1545
        ats_ip_copy(&_ret_sockaddr, peer->GetIP());
 
1546
        _ret_sockaddr.port() =  htons(static_cast<ParentSiblingPeer*>(peer)->GetProxyPort());
1547
1547
        _ret_status = ICP_LOOKUP_FOUND;
1548
1548
 
1549
1549
        Debug("icp",
1550
 
              "ICP Response HIT for Id=%d from [%s:%d] return [%s:%d]",
1551
 
              _sequence_number, inet_ntoa(*peer->GetIP()), peer->GetPort(),
1552
 
              inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
 
1550
          "ICP Response HIT for Id=%d from [%s] return [%s]",
 
1551
          _sequence_number,
 
1552
          ats_ip_nptop(peer->GetIP(), ipb, sizeof(ipb)),
 
1553
          ats_ip_nptop(&_ret_sockaddr, ipb2, sizeof(ipb2))
 
1554
        );
1553
1555
        return EVENT_DONE;
1554
1556
      }
1555
1557
    case ICP_OP_MISS:
1557
1559
    case ICP_OP_MISS_NOFETCH:
1558
1560
    case ICP_OP_DENIED:
1559
1561
      {
1560
 
        Debug("icp", "ICP MISS response for Id=%d from [%s:%d]",
1561
 
              _sequence_number, inet_ntoa(*peer->GetIP()), peer->GetPort());
 
1562
        Debug("icp", "ICP MISS response for Id=%d from [%s]",
 
1563
          _sequence_number, ats_ip_nptop(peer->GetIP(), ipb, sizeof(ipb)));
1562
1564
        // "received_replies" is only for Peers who we expect a reply
1563
1565
        //  from (Peers which are in the expected_replies_list).
1564
1566
        int Id = peer->GetPeerID();
1600
1602
            }
1601
1603
          }
1602
1604
          if (p) {
1603
 
            _ret_sockaddr.sin_addr.s_addr = (p->GetIP())->s_addr;
1604
 
            _ret_sockaddr.sin_port = htons(((ParentSiblingPeer *) p)->GetProxyPort());
 
1605
            ats_ip_copy(&_ret_sockaddr, p->GetIP());
 
1606
            _ret_sockaddr.port() = htons(static_cast<ParentSiblingPeer*>(p)->GetProxyPort());
1605
1607
            _ret_status = ICP_LOOKUP_FOUND;
1606
1608
 
1607
 
            Debug("icp", "ICP ALL MISS(1) for Id=%d return [%s:%d]",
1608
 
                  _sequence_number, inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
 
1609
            Debug("icp", "ICP ALL MISS(1) for Id=%d return [%s]",
 
1610
              _sequence_number, ats_ip_nptop(&_ret_sockaddr, ipb, sizeof(ipb)));
1609
1611
            return EVENT_DONE;
1610
1612
          }
1611
1613
        }
1612
 
        Debug("icp", "ICP ALL MISS(2) for Id=%d return [%s:%d]",
1613
 
              _sequence_number, inet_ntoa(_ret_sockaddr.sin_addr), ntohs(_ret_sockaddr.sin_port));
 
1614
        Debug("icp", "ICP ALL MISS(2) for Id=%d return [%s]",
 
1615
          _sequence_number, ats_ip_nptop(&_ret_sockaddr, ipb, sizeof(ipb)));
1614
1616
        return EVENT_DONE;
1615
1617
      }
1616
1618
    default:
1617
1619
      {
1618
1620
        ICP_INCREMENT_DYN_STAT(invalid_icp_query_response_stat);
1619
 
        unsigned char x[4];
1620
 
        *(uint32_t *) & x = (uint32_t) peer->GetIP()->s_addr;
1621
1621
        // coverity[uninit_use_in_call]
1622
 
        Warning("Invalid ICP response, op=%d reqno=%d ip=%d.%d.%d.%d",
1623
 
                m->h.opcode, m->h.requestno, x[0], x[1], x[2], x[3]);
 
1622
        Warning("Invalid ICP response, op=%d reqno=%d ip=%s",
 
1623
          m->h.opcode, m->h.requestno, ats_ip_ntop(peer->GetIP(), ipb, sizeof(ipb)));
1624
1624
        return EVENT_CONT;      // wait for more responses
1625
1625
      }
1626
1626
 
1736
1736
  mhdr->msg_name = (caddr_t) 0;
1737
1737
  mhdr->msg_namelen = 0;
1738
1738
  // TODO: The following is just awkward
1739
 
#if !defined(linux) && !defined(freebsd) && !defined(darwin) && !defined(solaris)
 
1739
#if !defined(linux) && !defined(freebsd) && !defined(darwin) && !defined(solaris) \
 
1740
 && !defined(openbsd)
1740
1741
  mhdr->msg_accrights = (caddr_t) 0;
1741
1742
  mhdr->msg_accrightslen = 0;
1742
1743
#elif !defined(solaris)
1866
1867
 
1867
1868
ICPProcessor::~ICPProcessor()
1868
1869
{
1869
 
#if defined (_WIN32)
1870
 
  if (0 < glShutdownInProgress)
1871
 
    return;
1872
 
#endif
1873
1870
  if (_ICPPeriodic) {
1874
1871
    MUTEX_TAKE_LOCK(_ICPPeriodic->mutex, this_ethread());
1875
1872
    _PeriodicEvent->cancel();
2021
2018
  // parents and siblings.
2022
2019
  //
2023
2020
  Pcfg = _ICPConfig->indexToPeerConfigData(0);
2024
 
  ink_strncpy(Pcfg->_hostname, "localhost", sizeof(Pcfg->_hostname));
 
2021
  ink_strlcpy(Pcfg->_hostname, "localhost", sizeof(Pcfg->_hostname));
2025
2022
  Pcfg->_ctype = PeerConfigData::CTYPE_LOCAL;
2026
2023
 
2027
2024
  // Get IP address for given interface
2028
 
  if (!mgmt_getAddrForIntr(GetConfig()->globalConfig()->ICPinterface(), &Pcfg->_ip_addr)) {
 
2025
  IpEndpoint tmp_ip;
 
2026
  if (!mgmt_getAddrForIntr(GetConfig()->globalConfig()->ICPinterface(), &tmp_ip.sa)) {
 
2027
    Pcfg->_ip_addr._family = AF_UNSPEC;
2029
2028
    // No IP address for given interface
2030
2029
    Warning("ICP interface [%s] has no IP address", GetConfig()->globalConfig()->ICPinterface());
2031
2030
    REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP interface has no IP address");
2032
 
    Pcfg->_ip_addr.s_addr = 0;
2033
2031
  } else {
2034
 
    Pcfg->_my_ip_addr.s_addr = Pcfg->_ip_addr.s_addr;
 
2032
    Pcfg->_my_ip_addr = Pcfg->_ip_addr = tmp_ip;
2035
2033
  }
2036
2034
  Pcfg->_proxy_port = 0;
2037
2035
  Pcfg->_icp_port = GetConfig()->globalConfig()->ICPport();
2038
2036
  Pcfg->_mc_member = 0;
2039
 
  Pcfg->_mc_ip_addr.s_addr = 0;
 
2037
  Pcfg->_mc_ip_addr._family = AF_UNSPEC;
2040
2038
  Pcfg->_mc_ttl = 0;
2041
2039
 
2042
2040
  //***************************************************
2059
2057
    // siblings are cluster members.  Note that in a cluster
2060
2058
    // configuration, "icp.config" is shared by all nodes.
2061
2059
    //
2062
 
    if (Pcfg->GetIP()->s_addr == _LocalPeer->GetIP()->s_addr)
 
2060
    if (Pcfg->GetIPAddr() == _LocalPeer->GetIP())
2063
2061
      continue;                 // ignore
2064
2062
 
2065
2063
    if ((type == PEER_PARENT) || (type == PEER_SIBLING)) {
2066
2064
 
2067
2065
      if (Pcfg->MultiCastMember()) {
2068
 
        mcP = FindPeer(Pcfg->GetMultiCastIP(), Pcfg->GetICPPort());
 
2066
        mcP = FindPeer(Pcfg->GetMultiCastIPAddr(), Pcfg->GetICPPort());
2069
2067
        if (!mcP) {
2070
2068
          //*********************************
2071
2069
          // Create multicast peer structure
2072
2070
          //*********************************
2073
 
          mcP = NEW(new MultiCastPeer(Pcfg->GetMultiCastIP(), Pcfg->GetICPPort(), Pcfg->GetMultiCastTTL(), this));
 
2071
          mcP = NEW(new MultiCastPeer(Pcfg->GetMultiCastIPAddr(), Pcfg->GetICPPort(), Pcfg->GetMultiCastTTL(), this));
2074
2072
          status = AddPeer(mcP);
2075
2073
          ink_assert(status);
2076
2074
          status = AddPeerToSendList(mcP);
2190
2188
  int status;
2191
2189
  int index;
2192
2190
  for (index = 0; index < (_nPeerList + 1); ++index) {
 
2191
    ip_port_text_buffer ipb, ipb2;
 
2192
 
2193
2193
    if ((P = _PeerList[index])) {
2194
2194
 
2195
2195
      if ((P->GetType() == PEER_PARENT)
2196
2196
          || (P->GetType() == PEER_SIBLING)) {
2197
2197
        ParentSiblingPeer *pPS = (ParentSiblingPeer *) P;
2198
2198
 
2199
 
        pPS->GetChan()->setRemote(pPS->GetIP()->s_addr, pPS->GetPort());
 
2199
        pPS->GetChan()->setRemote(pPS->GetIP());
2200
2200
 
2201
2201
      } else if (P->GetType() == PEER_MULTICAST) {
2202
2202
        MultiCastPeer *pMC = (MultiCastPeer *) P;
2203
2203
        ink_assert(_mcastCB_handler != NULL);
2204
 
        status = pMC->GetSendChan()->setup_mc_send(pMC->GetIP()->s_addr, pMC->GetPort(), _LocalPeer->GetIP()->s_addr,
2205
 
#ifdef _WIN32
2206
 
                                                   _LocalPeer->GetPort(),
2207
 
#else
2208
 
                                                   0,
2209
 
#endif
2210
 
                                                   NON_BLOCKING, pMC->GetTTL(), DISABLE_MC_LOOPBACK, _mcastCB_handler);
 
2204
        status = pMC->GetSendChan()->setup_mc_send(pMC->GetIP(), _LocalPeer->GetIP(), NON_BLOCKING, pMC->GetTTL(), DISABLE_MC_LOOPBACK, _mcastCB_handler);
2211
2205
        if (status) {
2212
 
          unsigned char x[4], y[4];
2213
 
          *(uint32_t *) & x = (uint32_t) pMC->GetIP()->s_addr;
2214
 
          *(uint32_t *) & y = (uint32_t) _LocalPeer->GetIP()->s_addr;
2215
2206
          // coverity[uninit_use_in_call]
2216
 
          Warning("ICP MC send setup failed, res=%d, ip=%d.%d.%d.%d:%d bind_ip=%d.%d.%d.%d:%d",
2217
 
                  status, x[0], x[1], x[2], x[3], pMC->GetPort(), y[0], y[1], y[2], y[3], 0);
 
2207
          Warning("ICP MC send setup failed, res=%d, ip=%s bind_ip=%s",
 
2208
            status,
 
2209
            ats_ip_nptop(pMC->GetIP(), ipb, sizeof(ipb)),
 
2210
            ats_ip_nptop(_LocalPeer->GetIP(), ipb2, sizeof(ipb2))
 
2211
          );
2218
2212
          REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP MC send setup failed");
2219
2213
          return 1;             // Failed
2220
2214
        }
2221
2215
 
2222
 
        status = pMC->GetRecvChan()->setup_mc_receive(pMC->GetIP()->s_addr,
2223
 
                                                      pMC->GetPort(),
 
2216
        status = pMC->GetRecvChan()->setup_mc_receive(pMC->GetIP(),
2224
2217
                                                      NON_BLOCKING, pMC->GetSendChan(), _mcastCB_handler);
2225
2218
        if (status) {
2226
 
          unsigned char x[4];
2227
 
          *(uint32_t *) & x = (uint32_t) pMC->GetIP()->s_addr;
2228
2219
          // coverity[uninit_use_in_call]
2229
 
          Warning("ICP MC recv setup failed, res=%d, ip=%d.%d.%d.%d:%d",
2230
 
                  status, x[0], x[1], x[2], x[3], pMC->GetPort());
 
2220
          Warning("ICP MC recv setup failed, res=%d, ip=%s",
 
2221
            status, ats_ip_nptop(pMC->GetIP(), ipb, sizeof(ipb)));
2231
2222
          REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "ICP MC recv setup failed");
2232
2223
          return 1;             // Failed
2233
2224
        }
2241
2232
  //
2242
2233
  ParentSiblingPeer *pPS = (ParentSiblingPeer *) ((Peer *) _LocalPeer);
2243
2234
 
2244
 
  pPS->GetChan()->setRemote(pPS->GetIP()->s_addr, pPS->GetPort());
 
2235
  pPS->GetChan()->setRemote(pPS->GetIP());
2245
2236
  return 0;                     // Success
2246
2237
}
2247
2238
 
2297
2288
  _ICPConfig->UpdateGlobalConfig();
2298
2289
  _ICPConfig->UpdatePeerConfig();
2299
2290
 
2300
 
  int status;
2301
 
  if ((status = BuildPeerList()) == 0) {
2302
 
    status = SetupListenSockets();
 
2291
  int status = -1;
 
2292
  if (_ICPConfig->globalConfig()->ICPconfigured()) {
 
2293
    if ((status = BuildPeerList()) == 0) {
 
2294
      status = SetupListenSockets();
 
2295
    }
 
2296
    DumpICPConfig();
2303
2297
  }
2304
 
  DumpICPConfig();
2305
2298
  return status;
2306
2299
}
2307
2300
 
2375
2368
    }                           // End of switch
2376
2369
 
2377
2370
  }                             // End of while
2378
 
#if !defined(_WIN32) && !defined(__GNUC__)
 
2371
#if !defined(__GNUC__)
2379
2372
_exit_while:                   // fix DEC warnings
2380
2373
#endif
2381
2374
  return RC_DONE;
2399
2392
  r->_ICPmsg.h.version = ~r->_ICPmsg.h.version; // bogus message
2400
2393
 
2401
2394
  Peer *lp = GetLocalPeer();
2402
 
  r->_sendMsgHdr.msg_name = (caddr_t) & (lp->GetSendChan())->sa;
2403
 
  r->_sendMsgHdr.msg_namelen = sizeof((lp->GetSendChan())->sa);
 
2395
  r->_sendMsgHdr.msg_name = (caddr_t) & (lp->GetSendChan())->addr;
 
2396
  r->_sendMsgHdr.msg_namelen = sizeof((lp->GetSendChan())->addr);
2404
2397
  udpNet.sendmsg_re(r, r, lp->GetSendFD(), &r->_sendMsgHdr);
2405
2398
}
2406
2399
 
2407
2400
Peer *
2408
 
ICPProcessor::GenericFindListPeer(struct in_addr *ip, int port, int validListItems, Ptr<Peer> *List)
 
2401
ICPProcessor::GenericFindListPeer(IpAddr const& ip, uint16_t port, int validListItems, Ptr<Peer> *List)
2409
2402
{
2410
2403
  Peer *P;
 
2404
  port = htons(port);
2411
2405
  for (int n = 0; n < validListItems; ++n) {
2412
2406
    if ((P = List[n])) {
2413
 
      if ((P->GetIP()->s_addr == ip->s_addr)
2414
 
          && ((port == -1) || (P->GetPort() == port)))
 
2407
      if ((P->GetIP() == ip)
 
2408
        && ((port == 0) || (ats_ip_port_cast(P->GetIP()) == port)))
2415
2409
        return P;
2416
2410
    }
2417
2411
  }
2418
 
  return (Peer *) 0;
 
2412
  return NULL;
2419
2413
}
2420
2414
 
2421
2415
Peer *
2422
 
ICPProcessor::FindPeer(struct in_addr * ip, int port)
 
2416
ICPProcessor::FindPeer(IpAddr const& ip, uint16_t port)
2423
2417
{
2424
2418
  // Find (Peer *) with the given (ip,port) on the global list (PeerList)
2425
2419
  return GenericFindListPeer(ip, port, (_nPeerList + 1), _PeerList);
2426
2420
}
2427
2421
 
2428
2422
Peer *
2429
 
ICPProcessor::FindSendListPeer(struct in_addr * ip, int port)
 
2423
ICPProcessor::FindSendListPeer(IpAddr const& ip, uint16_t port)
2430
2424
{
2431
2425
  // Find (Peer *) with the given (ip,port) on the
2432
2426
  //  scheduler list (SendPeerList)
2434
2428
}
2435
2429
 
2436
2430
Peer *
2437
 
ICPProcessor::FindRecvListPeer(struct in_addr * ip, int port)
 
2431
ICPProcessor::FindRecvListPeer(IpAddr const& ip, uint16_t port)
2438
2432
{
2439
2433
  // Find (Peer *) with the given (ip,port) on the
2440
2434
  //  receive list (RecvPeerList)
2451
2445
  //
2452
2446
  // Make sure no duplicate exists
2453
2447
  //
2454
 
  if (FindPeer(P->GetIP(), P->GetPort())) {
2455
 
    unsigned char x[4];
2456
 
    *(uint32_t *) & x = (uint32_t) P->GetIP()->s_addr;
 
2448
  if (FindPeer(P->GetIP())) {
 
2449
    ip_port_text_buffer x;
2457
2450
    // coverity[uninit_use_in_call]
2458
 
    Warning("bad icp.config, multiple peer definitions for ip=%d.%d.%d.%d", x[0], x[1], x[2], x[3]);
 
2451
    Warning("bad icp.config, multiple peer definitions for ip=%s", ats_ip_nptop(P->GetIP(), x, sizeof(x)));
2459
2452
    REC_SignalWarning(REC_SIGNAL_CONFIG_ERROR, "bad icp.config, multiple peer definitions");
2460
2453
 
2461
2454
    return 0;                   // Not added
2480
2473
  // Returns 1 - added; 0 - Not added
2481
2474
 
2482
2475
  // Assert that no duplicate exists
2483
 
  ink_assert(FindRecvListPeer(P->GetIP(), P->GetPort()) == 0);
 
2476
  ink_assert(FindRecvListPeer(IpAddr(P->GetIP()), ats_ip_port_host_order(P->GetIP())) == 0);
2484
2477
 
2485
2478
  if (_nRecvPeerList + 1 < RECV_PEER_LIST_SIZE) {
2486
2479
    _nRecvPeerList++;
2499
2492
  // Returns 1 - added; 0 - Not added
2500
2493
 
2501
2494
  // Assert that no duplicate exists
2502
 
  ink_assert(FindSendListPeer(P->GetIP(), P->GetPort()) == 0);
 
2495
  ink_assert(FindSendListPeer(IpAddr(P->GetIP()), ats_ip_port_host_order(P->GetIP())) == 0);
2503
2496
 
2504
2497
  if (_nSendPeerList + 1 < SEND_PEER_LIST_SIZE) {
2505
2498
    _nSendPeerList++;