Example #1
0
static int clear_affinity(int ifindex, int protocol,
                          unsigned laddr, unsigned lport,
                          unsigned raddr, unsigned rport)
{
  struct sfc_aff_clear sac;
  int rc, affinity_fd;

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

  if( log_level )
    printf("> %s %s:%d %s:%d ifindex %d clear\n", proto_to_str(protocol),
           ip_str(laddr), ntohs(lport), ip_str(raddr), ntohs(rport), ifindex);

  sac.ifindex = ifindex;
  sac.protocol = protocol;
  sac.daddr = laddr;
  sac.dport = lport;
  sac.saddr = raddr;
  sac.sport = rport;
  sac.err_out = sfc_aff_no_error;
  rc = ioctl(affinity_fd, SFC_AFF_CLEAR, &sac);
  if( sac.err_out != sfc_aff_no_error || rc != 0 ) {
    err("%s: ERROR: Failed to clear affinity\n", me);
    err("%s:        %s %s:%d %s:%d ifindex %d\n", me, proto_to_str(protocol),
        ip_str(laddr), ntohs(lport), ip_str(raddr), ntohs(rport), ifindex);
    err("%s:        errno=%d %s\n", me, errno, strerror(errno));
    if( sac.err_out != sfc_aff_no_error )
      err("%s:        err=%d %s\n",
          me, (int) sac.err_out, sfc_aff_err_msg(sac.err_out));
    return 0;
  }
  return 1;
}
Example #2
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)));
}
Example #3
0
static int set_affinity(int ifindex, int protocol,
                        unsigned laddr, unsigned lport,
                        unsigned raddr, unsigned rport, int rxq, int cpu)
{
  struct sfc_aff_set sas;
  int rc, affinity_fd;

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

  if( log_level )
    printf("> %s %s:%d %s:%d ifindex %d rxq %d cpu %d\n",
           proto_to_str(protocol), ip_str(laddr), ntohs(lport),
           ip_str(raddr), ntohs(rport), ifindex, rxq, cpu);

  sas.cpu = cpu;
  sas.rxq = rxq;
  sas.ifindex = ifindex;
  sas.protocol = protocol;
  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( sas.err_out != sfc_aff_no_error || rc != 0 ) {
    err("%s: ERROR: Failed to set affinity\n", me);
    err("%s:        %s %s:%d %s:%d ifindex %d rxq %d cpu %d\n",
        me, proto_to_str(protocol), ip_str(laddr), ntohs(lport), ip_str(raddr),
        ntohs(rport), ifindex, rxq, cpu);
    err("%s:        errno=%d %s\n", me, errno, strerror(errno));
    if( sas.err_out != sfc_aff_no_error )
      err("%s:        err=%d %s\n",
          me, (int) sas.err_out, sfc_aff_err_msg(sas.err_out));
    return 0;
  }
  return 1;
}