[BACK]Return to npf_inet.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / net / npf

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/net/npf/npf_inet.c between version 1.37.12.5 and 1.37.12.6

version 1.37.12.5, 2018/04/16 02:00:08 version 1.37.12.6, 2018/09/06 06:56:44
Line 230  npf_fetch_tcpopts(npf_cache_t *npc, uint
Line 230  npf_fetch_tcpopts(npf_cache_t *npc, uint
         nbuf_t *nbuf = npc->npc_nbuf;          nbuf_t *nbuf = npc->npc_nbuf;
         const struct tcphdr *th = npc->npc_l4.tcp;          const struct tcphdr *th = npc->npc_l4.tcp;
         int cnt, optlen = 0;          int cnt, optlen = 0;
         bool setmss = false;  
         uint8_t *cp, opt;          uint8_t *cp, opt;
         uint8_t val;          uint8_t val;
         bool ok;          bool ok;
Line 246  npf_fetch_tcpopts(npf_cache_t *npc, uint
Line 245  npf_fetch_tcpopts(npf_cache_t *npc, uint
         }          }
         KASSERT(cnt <= MAX_TCPOPTLEN);          KASSERT(cnt <= MAX_TCPOPTLEN);
   
         /* Determine if we want to set or get the mss. */  
         if (mss) {  
                 setmss = (*mss != 0);  
         }  
   
         /* Fetch all the options at once. */          /* Fetch all the options at once. */
         nbuf_reset(nbuf);          nbuf_reset(nbuf);
         const int step = npc->npc_hlen + sizeof(struct tcphdr);          const int step = npc->npc_hlen + sizeof(struct tcphdr);
Line 279  npf_fetch_tcpopts(npf_cache_t *npc, uint
Line 273  npf_fetch_tcpopts(npf_cache_t *npc, uint
                         if (optlen != TCPOLEN_MAXSEG)                          if (optlen != TCPOLEN_MAXSEG)
                                 continue;                                  continue;
                         if (mss) {                          if (mss) {
                                 if (setmss) {                                  memcpy(mss, cp + 2, sizeof(uint16_t));
                                         memcpy(cp + 2, mss, sizeof(uint16_t));  
                                 } else {  
                                         memcpy(mss, cp + 2, sizeof(uint16_t));  
                                 }  
                         }                          }
                         break;                          break;
                 case TCPOPT_WINDOW:                  case TCPOPT_WINDOW:
Line 305  done:
Line 295  done:
         return ok;          return ok;
 }  }
   
   /*
    * npf_set_mss: set the MSS.
    */
   bool
   npf_set_mss(npf_cache_t *npc, uint16_t mss, uint16_t *old, uint16_t *new,
       bool *mid)
   {
           nbuf_t *nbuf = npc->npc_nbuf;
           const struct tcphdr *th = npc->npc_l4.tcp;
           int cnt, optlen = 0;
           uint8_t *cp, *base, opt;
           bool ok;
   
           KASSERT(npf_iscached(npc, NPC_IP46));
           KASSERT(npf_iscached(npc, NPC_TCP));
   
           /* Determine if there are any TCP options, get their length. */
           cnt = (th->th_off << 2) - sizeof(struct tcphdr);
           if (cnt <= 0) {
                   /* No options. */
                   return false;
           }
           KASSERT(cnt <= MAX_TCPOPTLEN);
   
           /* Fetch all the options at once. */
           nbuf_reset(nbuf);
           const int step = npc->npc_hlen + sizeof(struct tcphdr);
           if ((base = nbuf_advance(nbuf, step, cnt)) == NULL) {
                   ok = false;
                   goto done;
           }
   
           /* Scan the options. */
           for (cp = base; cnt > 0; cnt -= optlen, cp += optlen) {
                   opt = cp[0];
                   if (opt == TCPOPT_EOL)
                           break;
                   if (opt == TCPOPT_NOP)
                           optlen = 1;
                   else {
                           if (cnt < 2)
                                   break;
                           optlen = cp[1];
                           if (optlen < 2 || optlen > cnt)
                                   break;
                   }
   
                   switch (opt) {
                   case TCPOPT_MAXSEG:
                           if (optlen != TCPOLEN_MAXSEG)
                                   continue;
                           if (((cp + 2) - base) % sizeof(uint16_t) != 0) {
                                   *mid = true;
                                   memcpy(&old[0], cp + 1, sizeof(uint16_t));
                                   memcpy(&old[1], cp + 3, sizeof(uint16_t));
                                   memcpy(cp + 2, &mss, sizeof(uint16_t));
                                   memcpy(&new[0], cp + 1, sizeof(uint16_t));
                                   memcpy(&new[1], cp + 3, sizeof(uint16_t));
                           } else {
                                   *mid = false;
                                   memcpy(cp + 2, &mss, sizeof(uint16_t));
                           }
                           break;
                   default:
                           break;
                   }
           }
   
           ok = true;
   done:
           if (nbuf_flag_p(nbuf, NBUF_DATAREF_RESET)) {
                   npf_recache(npc);
           }
           return ok;
   }
   
 static int  static int
 npf_cache_ip(npf_cache_t *npc, nbuf_t *nbuf)  npf_cache_ip(npf_cache_t *npc, nbuf_t *nbuf)
 {  {

Legend:
Removed from v.1.37.12.5  
changed lines
  Added in v.1.37.12.6

CVSweb <webmaster@jp.NetBSD.org>