Diff for /qemu/net/tap.c between versions 1.1.1.3 and 1.1.1.4

version 1.1.1.3, 2018/04/24 18:32:53 version 1.1.1.4, 2018/04/24 18:42:34
Line 57  typedef struct TAPState { Line 57  typedef struct TAPState {
     uint8_t buf[TAP_BUFSIZE];      uint8_t buf[TAP_BUFSIZE];
     unsigned int read_poll : 1;      unsigned int read_poll : 1;
     unsigned int write_poll : 1;      unsigned int write_poll : 1;
     unsigned int has_vnet_hdr : 1;  
     unsigned int using_vnet_hdr : 1;      unsigned int using_vnet_hdr : 1;
     unsigned int has_ufo: 1;      unsigned int has_ufo: 1;
     VHostNetState *vhost_net;      VHostNetState *vhost_net;
       unsigned host_vnet_hdr_len;
 } TAPState;  } TAPState;
   
 static int launch_script(const char *setup_script, const char *ifname, int fd);  static int launch_script(const char *setup_script, const char *ifname, int fd);
Line 121  static ssize_t tap_receive_iov(VLANClien Line 121  static ssize_t tap_receive_iov(VLANClien
     TAPState *s = DO_UPCAST(TAPState, nc, nc);      TAPState *s = DO_UPCAST(TAPState, nc, nc);
     const struct iovec *iovp = iov;      const struct iovec *iovp = iov;
     struct iovec iov_copy[iovcnt + 1];      struct iovec iov_copy[iovcnt + 1];
     struct virtio_net_hdr hdr = { 0, };      struct virtio_net_hdr_mrg_rxbuf hdr = { };
   
     if (s->has_vnet_hdr && !s->using_vnet_hdr) {      if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
         iov_copy[0].iov_base = &hdr;          iov_copy[0].iov_base = &hdr;
         iov_copy[0].iov_len =  sizeof(hdr);          iov_copy[0].iov_len =  s->host_vnet_hdr_len;
         memcpy(&iov_copy[1], iov, iovcnt * sizeof(*iov));          memcpy(&iov_copy[1], iov, iovcnt * sizeof(*iov));
         iovp = iov_copy;          iovp = iov_copy;
         iovcnt++;          iovcnt++;
Line 139  static ssize_t tap_receive_raw(VLANClien Line 139  static ssize_t tap_receive_raw(VLANClien
     TAPState *s = DO_UPCAST(TAPState, nc, nc);      TAPState *s = DO_UPCAST(TAPState, nc, nc);
     struct iovec iov[2];      struct iovec iov[2];
     int iovcnt = 0;      int iovcnt = 0;
     struct virtio_net_hdr hdr = { 0, };      struct virtio_net_hdr_mrg_rxbuf hdr = { };
   
     if (s->has_vnet_hdr) {      if (s->host_vnet_hdr_len) {
         iov[iovcnt].iov_base = &hdr;          iov[iovcnt].iov_base = &hdr;
         iov[iovcnt].iov_len  = sizeof(hdr);          iov[iovcnt].iov_len  = s->host_vnet_hdr_len;
         iovcnt++;          iovcnt++;
     }      }
   
Line 159  static ssize_t tap_receive(VLANClientSta Line 159  static ssize_t tap_receive(VLANClientSta
     TAPState *s = DO_UPCAST(TAPState, nc, nc);      TAPState *s = DO_UPCAST(TAPState, nc, nc);
     struct iovec iov[1];      struct iovec iov[1];
   
     if (s->has_vnet_hdr && !s->using_vnet_hdr) {      if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
         return tap_receive_raw(nc, buf, size);          return tap_receive_raw(nc, buf, size);
     }      }
   
Line 202  static void tap_send(void *opaque) Line 202  static void tap_send(void *opaque)
             break;              break;
         }          }
   
         if (s->has_vnet_hdr && !s->using_vnet_hdr) {          if (s->host_vnet_hdr_len && !s->using_vnet_hdr) {
             buf  += sizeof(struct virtio_net_hdr);              buf  += s->host_vnet_hdr_len;
             size -= sizeof(struct virtio_net_hdr);              size -= s->host_vnet_hdr_len;
         }          }
   
         size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);          size = qemu_send_packet_async(&s->nc, buf, size, tap_send_completed);
Line 229  int tap_has_vnet_hdr(VLANClientState *nc Line 229  int tap_has_vnet_hdr(VLANClientState *nc
   
     assert(nc->info->type == NET_CLIENT_TYPE_TAP);      assert(nc->info->type == NET_CLIENT_TYPE_TAP);
   
     return s->has_vnet_hdr;      return !!s->host_vnet_hdr_len;
   }
   
   int tap_has_vnet_hdr_len(VLANClientState *nc, int len)
   {
       TAPState *s = DO_UPCAST(TAPState, nc, nc);
   
       assert(nc->info->type == NET_CLIENT_TYPE_TAP);
   
       return tap_probe_vnet_hdr_len(s->fd, len);
   }
   
   void tap_set_vnet_hdr_len(VLANClientState *nc, int len)
   {
       TAPState *s = DO_UPCAST(TAPState, nc, nc);
   
       assert(nc->info->type == NET_CLIENT_TYPE_TAP);
       assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) ||
              len == sizeof(struct virtio_net_hdr));
   
       tap_fd_set_vnet_hdr_len(s->fd, len);
       s->host_vnet_hdr_len = len;
 }  }
   
 void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr)  void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr)
Line 239  void tap_using_vnet_hdr(VLANClientState  Line 260  void tap_using_vnet_hdr(VLANClientState 
     using_vnet_hdr = using_vnet_hdr != 0;      using_vnet_hdr = using_vnet_hdr != 0;
   
     assert(nc->info->type == NET_CLIENT_TYPE_TAP);      assert(nc->info->type == NET_CLIENT_TYPE_TAP);
     assert(s->has_vnet_hdr == using_vnet_hdr);      assert(!!s->host_vnet_hdr_len == using_vnet_hdr);
   
     s->using_vnet_hdr = using_vnet_hdr;      s->using_vnet_hdr = using_vnet_hdr;
 }  }
Line 248  void tap_set_offload(VLANClientState *nc Line 269  void tap_set_offload(VLANClientState *nc
                      int tso6, int ecn, int ufo)                       int tso6, int ecn, int ufo)
 {  {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);      TAPState *s = DO_UPCAST(TAPState, nc, nc);
       if (s->fd < 0) {
           return;
       }
   
     return tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);      tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
 }  }
   
 static void tap_cleanup(VLANClientState *nc)  static void tap_cleanup(VLANClientState *nc)
Line 258  static void tap_cleanup(VLANClientState  Line 282  static void tap_cleanup(VLANClientState 
   
     if (s->vhost_net) {      if (s->vhost_net) {
         vhost_net_cleanup(s->vhost_net);          vhost_net_cleanup(s->vhost_net);
           s->vhost_net = NULL;
     }      }
   
     qemu_purge_queued_packets(nc);      qemu_purge_queued_packets(nc);
Line 268  static void tap_cleanup(VLANClientState  Line 293  static void tap_cleanup(VLANClientState 
     tap_read_poll(s, 0);      tap_read_poll(s, 0);
     tap_write_poll(s, 0);      tap_write_poll(s, 0);
     close(s->fd);      close(s->fd);
       s->fd = -1;
 }  }
   
 static void tap_poll(VLANClientState *nc, bool enable)  static void tap_poll(VLANClientState *nc, bool enable)
Line 310  static TAPState *net_tap_fd_init(VLANSta Line 336  static TAPState *net_tap_fd_init(VLANSta
     s = DO_UPCAST(TAPState, nc, nc);      s = DO_UPCAST(TAPState, nc, nc);
   
     s->fd = fd;      s->fd = fd;
     s->has_vnet_hdr = vnet_hdr != 0;      s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
     s->using_vnet_hdr = 0;      s->using_vnet_hdr = 0;
     s->has_ufo = tap_probe_has_ufo(s->fd);      s->has_ufo = tap_probe_has_ufo(s->fd);
     tap_set_offload(&s->nc, 0, 0, 0, 0, 0);      tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
Line 465  int net_init_tap(QemuOpts *opts, Monitor Line 491  int net_init_tap(QemuOpts *opts, Monitor
         }          }
     }      }
   
     if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd"))) {      if (qemu_opt_get_bool(opts, "vhost", !!qemu_opt_get(opts, "vhostfd") ||
                             qemu_opt_get_bool(opts, "vhostforce", false))) {
         int vhostfd, r;          int vhostfd, r;
           bool force = qemu_opt_get_bool(opts, "vhostforce", false);
         if (qemu_opt_get(opts, "vhostfd")) {          if (qemu_opt_get(opts, "vhostfd")) {
             r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd"));              r = net_handle_fd_param(mon, qemu_opt_get(opts, "vhostfd"));
             if (r == -1) {              if (r == -1) {
Line 476  int net_init_tap(QemuOpts *opts, Monitor Line 504  int net_init_tap(QemuOpts *opts, Monitor
         } else {          } else {
             vhostfd = -1;              vhostfd = -1;
         }          }
         s->vhost_net = vhost_net_init(&s->nc, vhostfd);          s->vhost_net = vhost_net_init(&s->nc, vhostfd, force);
         if (!s->vhost_net) {          if (!s->vhost_net) {
             error_report("vhost-net requested but could not be initialized");              error_report("vhost-net requested but could not be initialized");
             return -1;              return -1;

Removed from v.1.1.1.3  
changed lines
  Added in v.1.1.1.4


unix.superglobalmegacorp.com