[Olsr-cvs] olsrd-current/src net_olsr.c,1.32,1.33

Bernd Petrovitsch (spam-protected)
Wed Nov 14 12:01:05 CET 2007


Update of /cvsroot/olsrd/olsrd-current/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv25997/src

Modified Files:
	net_olsr.c 
Log Message:
* fixed a bug in the olsr_netmask_to_prefix() function which produced
  invalid netmasks if feeded with 255.255.255.255.
  Thnaks to Hannes Gredler <(spam-protected)> for pointing to that
  function.
* replaced the second "(for()" loop with a simple "switch()" for the
  9 legal/valid/supported values of 1 byte netmasks. So we can now detect
  illegal ones and report this with returning UINT_MAX as prefix length
  (and writing something out).
  That really shouldn't happen but God knows what some clowns sends over
  the net to annoy us.


Index: net_olsr.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/net_olsr.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** net_olsr.c	8 Nov 2007 22:47:41 -0000	1.32
--- net_olsr.c	14 Nov 2007 11:01:03 -0000	1.33
***************
*** 498,506 ****
  olsr_netmask_to_prefix(const union olsr_ip_addr *adr)
  {
- #if !defined(NODEBUG) && defined(DEBUG)
    struct ipaddr_str buf;
- #endif
    olsr_u16_t prefix = 0;
-   olsr_u8_t tmp;
    const olsr_u8_t * const a_end = adr->v6.s6_addr+olsr_cnf->ipsize;
    const olsr_u8_t *a;
--- 498,503 ----
***************
*** 509,520 ****
      prefix += 8;
    }
!   for (tmp = *a; tmp > 0; tmp <<= 1) {
!     prefix++;
    }
- 
  #ifdef DEBUG
    OLSR_PRINTF(3, "Netmask: %s = Prefix %d\n", olsr_ip_to_string(&buf, adr), prefix);
  #endif
- 
    return prefix;
  }
--- 506,530 ----
      prefix += 8;
    }
!   if (a < a_end) {
!     /* handle the last byte */
!     switch (*a) {
!     case   0: prefix += 0; break;
!     case 128: prefix += 1; break;
!     case 192: prefix += 2; break;
!     case 224: prefix += 3; break;
!     case 240: prefix += 4; break;
!     case 248: prefix += 5; break;
!     case 252: prefix += 6; break;
!     case 254: prefix += 7; break;
!     case 255: prefix += 8; break; /* Shouldn't happen */
!     default:
!       OLSR_PRINTF(0, "%s: Got bogus netmask %s\n", __func__, olsr_ip_to_string(&buf, adr));    
!       prefix = USHRT_MAX;
!       break;
!     }
    }
  #ifdef DEBUG
    OLSR_PRINTF(3, "Netmask: %s = Prefix %d\n", olsr_ip_to_string(&buf, adr), prefix);
  #endif
    return prefix;
  }





More information about the Olsr-cvs mailing list