Diff for /qemu/slirp/if.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2018/04/24 16:43:55 version 1.1.1.3, 2018/04/24 16:49:15
Line 7 Line 7
   
 #include <slirp.h>  #include <slirp.h>
   
 int if_mtu, if_mru;  
 int if_comp;  
 int if_maxlinkhdr;  
 int     if_queued = 0;                  /* Number of packets queued so far */  int     if_queued = 0;                  /* Number of packets queued so far */
 int     if_thresh = 10;                 /* Number of packets queued before we start sending  
                                          * (to prevent allocing too many mbufs) */  
   
 struct  mbuf if_fastq;                  /* fast queue (for interactive data) */  struct  mbuf if_fastq;                  /* fast queue (for interactive data) */
 struct  mbuf if_batchq;                 /* queue for non-interactive data */  struct  mbuf if_batchq;                 /* queue for non-interactive data */
Line 41  ifs_remque(ifm) Line 36  ifs_remque(ifm)
 void  void
 if_init()  if_init()
 {  {
 #if 0  
         /*  
          * Set if_maxlinkhdr to 48 because it's 40 bytes for TCP/IP,  
          * and 8 bytes for PPP, but need to have it on an 8byte boundary  
          */  
 #ifdef USE_PPP  
         if_maxlinkhdr = 48;  
 #else  
         if_maxlinkhdr = 40;  
 #endif  
 #else  
         /* 2 for alignment, 14 for ethernet, 40 for TCP/IP */  
         if_maxlinkhdr = 2 + 14 + 40;  
 #endif  
         if_mtu = 1500;  
         if_mru = 1500;  
         if_comp = IF_AUTOCOMP;  
         if_fastq.ifq_next = if_fastq.ifq_prev = &if_fastq;          if_fastq.ifq_next = if_fastq.ifq_prev = &if_fastq;
         if_batchq.ifq_next = if_batchq.ifq_prev = &if_batchq;          if_batchq.ifq_next = if_batchq.ifq_prev = &if_batchq;
         //      sl_compress_init(&comp_s);          //      sl_compress_init(&comp_s);
Line 77  writen(fd, bptr, n) Line 55  writen(fd, bptr, n)
 {  {
         int ret;          int ret;
         int total;          int total;
           
         /* This should succeed most of the time */          /* This should succeed most of the time */
         ret = send(fd, bptr, n,0);          ret = send(fd, bptr, n,0);
         if (ret == n || ret <= 0)          if (ret == n || ret <= 0)
            return ret;             return ret;
           
         /* Didn't write everything, go into the loop */          /* Didn't write everything, go into the loop */
         total = ret;          total = ret;
         while (n > total) {          while (n > total) {
Line 97  writen(fd, bptr, n) Line 75  writen(fd, bptr, n)
 /*  /*
  * if_input - read() the tty, do "top level" processing (ie: check for any escapes),   * if_input - read() the tty, do "top level" processing (ie: check for any escapes),
  * and pass onto (*ttyp->if_input)   * and pass onto (*ttyp->if_input)
  *    *
  * XXXXX Any zeros arriving by themselves are NOT placed into the arriving packet.   * XXXXX Any zeros arriving by themselves are NOT placed into the arriving packet.
  */   */
 #define INBUFF_SIZE 2048 /* XXX */  #define INBUFF_SIZE 2048 /* XXX */
Line 107  if_input(ttyp) Line 85  if_input(ttyp)
 {  {
         u_char if_inbuff[INBUFF_SIZE];          u_char if_inbuff[INBUFF_SIZE];
         int if_n;          int if_n;
           
         DEBUG_CALL("if_input");          DEBUG_CALL("if_input");
         DEBUG_ARG("ttyp = %lx", (long)ttyp);          DEBUG_ARG("ttyp = %lx", (long)ttyp);
           
         if_n = recv(ttyp->fd, (char *)if_inbuff, INBUFF_SIZE,0);          if_n = recv(ttyp->fd, (char *)if_inbuff, INBUFF_SIZE,0);
           
         DEBUG_MISC((dfd, " read %d bytes\n", if_n));          DEBUG_MISC((dfd, " read %d bytes\n", if_n));
           
         if (if_n <= 0) {          if (if_n <= 0) {
                 if (if_n == 0 || (errno != EINTR && errno != EAGAIN)) {                  if (if_n == 0 || (errno != EINTR && errno != EAGAIN)) {
                         if (ttyp->up)                          if (ttyp->up)
Line 138  if_input(ttyp) Line 116  if_input(ttyp)
                 }                  }
         }          }
         ttyp->ones = ttyp->zeros = 0;          ttyp->ones = ttyp->zeros = 0;
           
         (*ttyp->if_input)(ttyp, if_inbuff, if_n);          (*ttyp->if_input)(ttyp, if_inbuff, if_n);
 }  }
 #endif    #endif
           
 /*  /*
  * if_output: Queue packet into an output queue.   * if_output: Queue packet into an output queue.
  * There are 2 output queue's, if_fastq and if_batchq.    * There are 2 output queue's, if_fastq and if_batchq.
  * Each output queue is a doubly linked list of double linked lists   * Each output queue is a doubly linked list of double linked lists
  * of mbufs, each list belonging to one "session" (socket).  This   * of mbufs, each list belonging to one "session" (socket).  This
  * way, we can output packets fairly by sending one packet from each   * way, we can output packets fairly by sending one packet from each
  * session, instead of all the packets from one session, then all packets   * session, instead of all the packets from one session, then all packets
  * from the next session, etc.  Packets on the if_fastq get absolute    * from the next session, etc.  Packets on the if_fastq get absolute
  * priority, but if one session hogs the link, it gets "downgraded"   * priority, but if one session hogs the link, it gets "downgraded"
  * to the batchq until it runs out of packets, then it'll return   * to the batchq until it runs out of packets, then it'll return
  * to the fastq (eg. if the user does an ls -alR in a telnet session,   * to the fastq (eg. if the user does an ls -alR in a telnet session,
Line 163  if_output(so, ifm) Line 141  if_output(so, ifm)
 {  {
         struct mbuf *ifq;          struct mbuf *ifq;
         int on_fastq = 1;          int on_fastq = 1;
           
         DEBUG_CALL("if_output");          DEBUG_CALL("if_output");
         DEBUG_ARG("so = %lx", (long)so);          DEBUG_ARG("so = %lx", (long)so);
         DEBUG_ARG("ifm = %lx", (long)ifm);          DEBUG_ARG("ifm = %lx", (long)ifm);
           
         /*          /*
          * First remove the mbuf from m_usedlist,           * First remove the mbuf from m_usedlist,
          * since we're gonna use m_next and m_prev ourselves           * since we're gonna use m_next and m_prev ourselves
Line 177  if_output(so, ifm) Line 155  if_output(so, ifm)
                 remque(ifm);                  remque(ifm);
                 ifm->m_flags &= ~M_USEDLIST;                  ifm->m_flags &= ~M_USEDLIST;
         }          }
           
         /*          /*
          * See if there's already a batchq list for this session.             * See if there's already a batchq list for this session.
          * This can include an interactive session, which should go on fastq,           * This can include an interactive session, which should go on fastq,
          * but gets too greedy... hence it'll be downgraded from fastq to batchq.           * but gets too greedy... hence it'll be downgraded from fastq to batchq.
          * We mustn't put this packet back on the fastq (or we'll send it out of order)           * We mustn't put this packet back on the fastq (or we'll send it out of order)
Line 193  if_output(so, ifm) Line 171  if_output(so, ifm)
                         goto diddit;                          goto diddit;
                 }                  }
         }          }
           
         /* No match, check which queue to put it on */          /* No match, check which queue to put it on */
         if (so && (so->so_iptos & IPTOS_LOWDELAY)) {          if (so && (so->so_iptos & IPTOS_LOWDELAY)) {
                 ifq = if_fastq.ifq_prev;                  ifq = if_fastq.ifq_prev;
Line 209  if_output(so, ifm) Line 187  if_output(so, ifm)
                 }                  }
         } else          } else
                 ifq = if_batchq.ifq_prev;                  ifq = if_batchq.ifq_prev;
           
         /* Create a new doubly linked list for this session */          /* Create a new doubly linked list for this session */
         ifm->ifq_so = so;          ifm->ifq_so = so;
         ifs_init(ifm);          ifs_init(ifm);
         insque(ifm, ifq);          insque(ifm, ifq);
           
 diddit:  diddit:
         ++if_queued;          ++if_queued;
           
         if (so) {          if (so) {
                 /* Update *_queued */                  /* Update *_queued */
                 so->so_queued++;                  so->so_queued++;
Line 229  diddit: Line 207  diddit:
                  * have been sent over the link                   * have been sent over the link
                  * (XXX These are arbitrary numbers, probably not optimal..)                   * (XXX These are arbitrary numbers, probably not optimal..)
                  */                   */
                 if (on_fastq && ((so->so_nqueued >= 6) &&                   if (on_fastq && ((so->so_nqueued >= 6) &&
                                  (so->so_nqueued - so->so_queued) >= 3)) {                                   (so->so_nqueued - so->so_queued) >= 3)) {
                           
                         /* Remove from current queue... */                          /* Remove from current queue... */
                         remque(ifm->ifs_next);                          remque(ifm->ifs_next);
                           
                         /* ...And insert in the new.  That'll teach ya! */                          /* ...And insert in the new.  That'll teach ya! */
                         insque(ifm->ifs_next, &if_batchq);                          insque(ifm->ifs_next, &if_batchq);
                 }                  }
Line 267  void Line 245  void
 if_start(void)  if_start(void)
 {  {
         struct mbuf *ifm, *ifqt;          struct mbuf *ifm, *ifqt;
           
         DEBUG_CALL("if_start");          DEBUG_CALL("if_start");
           
         if (if_queued == 0)          if (if_queued == 0)
            return; /* Nothing to do */             return; /* Nothing to do */
           
  again:   again:
         /* check if we can really output */          /* check if we can really output */
         if (!slirp_can_output())          if (!slirp_can_output())
Line 290  if_start(void) Line 268  if_start(void)
                    ifm = next_m;                     ifm = next_m;
                 else                  else
                    ifm = if_batchq.ifq_next;                     ifm = if_batchq.ifq_next;
                   
                 /* Set which packet to send on next iteration */                  /* Set which packet to send on next iteration */
                 next_m = ifm->ifq_next;                  next_m = ifm->ifq_next;
         }          }
Line 298  if_start(void) Line 276  if_start(void)
         ifqt = ifm->ifq_prev;          ifqt = ifm->ifq_prev;
         remque(ifm);          remque(ifm);
         --if_queued;          --if_queued;
           
         /* If there are more packets for this session, re-queue them */          /* If there are more packets for this session, re-queue them */
         if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) {          if (ifm->ifs_next != /* ifm->ifs_prev != */ ifm) {
                 insque(ifm->ifs_next, ifqt);                  insque(ifm->ifs_next, ifqt);
                 ifs_remque(ifm);                  ifs_remque(ifm);
         }          }
           
         /* Update so_queued */          /* Update so_queued */
         if (ifm->ifq_so) {          if (ifm->ifq_so) {
                 if (--ifm->ifq_so->so_queued == 0)                  if (--ifm->ifq_so->so_queued == 0)
                    /* If there's no more queued, reset nqueued */                     /* If there's no more queued, reset nqueued */
                    ifm->ifq_so->so_nqueued = 0;                     ifm->ifq_so->so_nqueued = 0;
         }          }
           
         /* Encapsulate the packet for sending */          /* Encapsulate the packet for sending */
         if_encap(ifm->m_data, ifm->m_len);          if_encap(ifm->m_data, ifm->m_len);
   

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


unix.superglobalmegacorp.com