예제 #1
0
static void set_affinity(int type, unsigned laddr, unsigned lport,
                         unsigned raddr, unsigned rport)
{
  struct sfc_aff_set sas;
  int affinity_fd, ifindex;
  int rc;

  if( override_ifindex == -2 ) {
    if( (ifindex = ip_to_ifindex(laddr)) < 0 ) {
      E(fprintf(stderr, LPF "Could not find ifindex for "IP4_FMT"\n",
                IP4_ARGS(laddr)));
      return;
    }
  }
  else {
    ifindex = override_ifindex;
  }

  affinity_fd = get_affinity_fd();
  if( affinity_fd < 0 )
    return;

  T(fprintf(stderr, LPF "%s(%s, "IP4PORT_FMT", "IP4PORT_FMT") => ifindex=%d\n",
            __FUNCTION__, type == SOCK_STREAM ? "tcp":"udp",
            IP4PORT_ARGS(laddr, lport), IP4PORT_ARGS(raddr, rport), ifindex));

  sas.cpu = override_cpu;
  sas.rxq = override_rxq;
  sas.ifindex = ifindex;
  sas.protocol = type == SOCK_STREAM ? IPPROTO_TCP : IPPROTO_UDP;
  sas.daddr = laddr;
  sas.dport = lport;
  sas.saddr = raddr;
  sas.sport = rport;
  sas.err_out = sfc_aff_no_error;
  rc = ioctl(affinity_fd, SFC_AFF_SET, &sas);
  if( rc != 0 )
    E(fprintf(stderr, LPF "Failed to set affinity (%d, %s) (%d, %s)\n",
              errno, strerror(errno), (int) sas.err_out,
              sfc_aff_err_msg(sas.err_out)));
}
예제 #2
0
static int do_clear_affinity(const char* protos, struct sockaddr_in la,
                             struct sockaddr_in ra)
{
  int proto = str_to_proto(protos);
  int i, ifindex;

  refresh_ip_list();

  if( la.sin_addr.s_addr == 0 ) {
    for( i = 0; i < ip_list_n; ++i )
      if( interface_driver_is(ip_list_name(i), "sfc") )
        clear_affinity(interface_to_ifindex(ip_list_name(i)), proto,
                       ip_list_ip(i), la.sin_port,
                       ra.sin_addr.s_addr, ra.sin_port);
    return 1;
  }
  else if( CI_IP_IS_MULTICAST(la.sin_addr.s_addr) ) {
    for( i = 0; i < ip_list_n; ++i )
      if( interface_is(ip_list_name(i), "sfc") )
        clear_affinity(interface_to_ifindex(ip_list_name(i)), proto,
                       la.sin_addr.s_addr, la.sin_port,
                       ra.sin_addr.s_addr, ra.sin_port);
    return 1;
  }
  else {
    ifindex = ip_to_ifindex(la.sin_addr.s_addr);
    if( ifindex < 0 ) {
      err("%s: ERROR: Can't find interface for IP %s\n",
          me, inet_ntoa(la.sin_addr));
      return 0;
    }
    clear_affinity(ifindex, proto,
                   la.sin_addr.s_addr, la.sin_port,
                   ra.sin_addr.s_addr, ra.sin_port);
    return 1;
  }
}