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

« back to all changes in this revision

Viewing changes to lib/wccp/WccpEndPoint.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:
23
23
# include "WccpUtil.h"
24
24
# include "WccpMeta.h"
25
25
# include <errno.h>
 
26
# include "ink_string.h"
26
27
// ------------------------------------------------------
27
28
namespace wccp {
 
29
 
 
30
#if defined IP_RECVDSTADDR
 
31
# define DSTADDR_SOCKOPT IP_RECVDSTADDR
 
32
# define DSTADDR_DATASIZE (CMSG_SPACE(sizeof(struct in_addr)))
 
33
# define dstaddr(x) (CMSG_DATA(x))
 
34
#elif defined IP_PKTINFO
 
35
# define DSTADDR_SOCKOPT IP_PKTINFO
 
36
# define DSTADDR_DATASIZE (CMSG_SPACE(sizeof(struct in_pktinfo)))
 
37
# define dstaddr(x) (&(((struct in_pktinfo *)(CMSG_DATA(x)))->ipi_addr))
 
38
#else
 
39
# error "can't determine socket option"
 
40
#endif 
 
41
 
28
42
// ------------------------------------------------------
29
43
Impl::GroupData::GroupData()
30
44
  : m_generation(0)
35
49
Impl::GroupData&
36
50
Impl::GroupData::setKey(char const* key) {
37
51
  m_use_security_key = true;
38
 
  memset(m_security_key, 0, SecurityComp::KEY_SIZE);
39
52
  strncpy(m_security_key, key, SecurityComp::KEY_SIZE);
40
53
  return *this;
41
54
}
95
108
 
96
109
  // Enable retrieval of destination address on packets.
97
110
  int ip_pktinfo_flag = 1;
98
 
  if (-1 == setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &ip_pktinfo_flag, sizeof(ip_pktinfo_flag))) {
 
111
  if (-1 == setsockopt(fd, IPPROTO_IP, DSTADDR_SOCKOPT, &ip_pktinfo_flag, sizeof(ip_pktinfo_flag))) {
99
112
    log_errno(LVL_FATAL, "Failed to enable destination address retrieval");
100
113
    this->close();
101
114
    return -errno;
132
145
  m_use_security_key = true;
133
146
  memset(m_security_key, 0, SecurityComp::KEY_SIZE);
134
147
  // Great. Have to cast or we get a link error.
135
 
  strncpy(m_security_key, key._ptr, std::min(key._size, static_cast<size_t>(SecurityComp::KEY_SIZE)));
 
148
  memcpy(m_security_key, key._ptr, std::min(key._size, static_cast<size_t>(SecurityComp::KEY_SIZE)));
136
149
}
137
150
 
138
151
SecurityOption
171
184
  IpHeader ip_header;
172
185
  static ssize_t const BUFFER_SIZE = 65536;
173
186
  char buffer[BUFFER_SIZE];
174
 
  static size_t const ANC_BUFFER_SIZE = CMSG_ALIGN(CMSG_SPACE(sizeof(in_pktinfo)));
 
187
  static size_t const ANC_BUFFER_SIZE = DSTADDR_DATASIZE;
175
188
  char anc_buffer[ANC_BUFFER_SIZE];
176
189
 
177
190
  if (ts::NO_FD == m_fd) return -ENOTCONN;
196
209
        anc;
197
210
        anc = CMSG_NXTHDR(&recv_hdr, anc)
198
211
  ) {
199
 
    if (anc->cmsg_level == IPPROTO_IP && anc->cmsg_type == IP_PKTINFO) {
200
 
      ip_header.m_dst = access_field(&in_pktinfo::ipi_addr, CMSG_DATA(anc)).s_addr;
 
212
    if (anc->cmsg_level == IPPROTO_IP && anc->cmsg_type == DSTADDR_SOCKOPT) {
 
213
      ip_header.m_dst = ((struct in_addr*)dstaddr(anc))->s_addr;
201
214
      break;
202
215
    }
203
216
  }
770
783
      );
771
784
    }
772
785
  }
 
786
  time_t then = ar_spot->m_recv.m_time; // used for comparisons later.
773
787
  ar_spot->m_recv.set(now, recv_id);
774
788
  ar_spot->m_generation = msg.m_router_view.getChangeNumber();
775
789
  router_idx = ar_spot - group.m_routers.begin();
801
815
      ac_spot->m_src.resize(group.m_routers.size());
802
816
      logf(LVL_INFO, "Added cache %s to view %d", ip_addr_to_str(cache.getAddr()), group.m_svc.getSvcId());
803
817
      view_changed = true;
 
818
    } else {
 
819
      // Check if the cache wasn't reported last time but was reported
 
820
      // this time. In that case we need to bump the view to trigger
 
821
      // assignment generation.
 
822
      if (ac_spot->m_src[router_idx].m_time != then) view_changed = true;
804
823
    }
805
824
    ac_spot->m_id.fill(cache);
806
825
    // If cache is this cache, update data in router record.