[Olsr-cvs] olsrd-current/src/bsd net.c, 1.37, 1.38 kernel_routes.c, 1.13, 1.14

Bernd Petrovitsch (spam-protected)
Fri Oct 5 00:27:33 CEST 2007


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

Modified Files:
	net.c kernel_routes.c 
Log Message:
* bug fixes and cleanups by John Hay <(spam-protected)> for FreeBSD

Index: net.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/bsd/net.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** net.c	7 Sep 2007 08:53:36 -0000	1.37
--- net.c	4 Oct 2007 22:27:31 -0000	1.38
***************
*** 728,731 ****
--- 728,735 ----
    struct msghdr mhdr;
    struct iovec iov;
+   union {
+ 	struct cmsghdr cmsg;
+   	unsigned char chdr[4096];
+   } cmu;
    struct cmsghdr *cm;
    struct sockaddr_dl *sdl;
***************
*** 737,745 ****
    char addrstr[INET6_ADDRSTRLEN];
    char iname[IFNAMSIZ];
-   unsigned char chdr[4096];
    int count;
  
!   bzero(&mhdr, sizeof(mhdr));
!   bzero(&iov, sizeof(iov));
  
    mhdr.msg_name = (caddr_t) from;
--- 741,748 ----
    char addrstr[INET6_ADDRSTRLEN];
    char iname[IFNAMSIZ];
    int count;
  
!   memset(&mhdr, 0, sizeof(mhdr));
!   memset(&iov, 0, sizeof(iov));
  
    mhdr.msg_name = (caddr_t) from;
***************
*** 747,754 ****
    mhdr.msg_iov = &iov;
    mhdr.msg_iovlen = 1;
!   mhdr.msg_control = (caddr_t) chdr;
!   mhdr.msg_controllen = sizeof (chdr);
  
!   iov.iov_len = MAXMESSAGESIZE;
    iov.iov_base = buf;
  
--- 750,757 ----
    mhdr.msg_iov = &iov;
    mhdr.msg_iovlen = 1;
!   mhdr.msg_control = (caddr_t) &cmu;
!   mhdr.msg_controllen = sizeof (cmu);
  
!   iov.iov_len = len;
    iov.iov_base = buf;
  
***************
*** 776,782 ****
    else
      {
!       cm = (struct cmsghdr *) chdr;
        sdl = (struct sockaddr_dl *) CMSG_DATA (cm);
!       bzero (iname, sizeof (iname));
        memcpy (iname, sdl->sdl_data, sdl->sdl_nlen);
      }
--- 779,785 ----
    else
      {
!       cm = &cmu.cmsg;
        sdl = (struct sockaddr_dl *) CMSG_DATA (cm);
!       memset (iname, 0, sizeof (iname));
        memcpy (iname, sdl->sdl_data, sdl->sdl_nlen);
      }

Index: kernel_routes.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/bsd/kernel_routes.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** kernel_routes.c	5 Sep 2007 16:17:36 -0000	1.13
--- kernel_routes.c	4 Oct 2007 22:27:31 -0000	1.14
***************
*** 224,227 ****
--- 224,235 ----
      memcpy(&sin6.sin6_addr.s6_addr, &nexthop->gateway.v6, sizeof(struct in6_addr));
  
+     memset(&sin6.sin6_addr.s6_addr, 0, 8);
+     sin6.sin6_addr.s6_addr[0] = 0xfe;
+     sin6.sin6_addr.s6_addr[1] = 0x80;
+     sin6.sin6_scope_id = nexthop->iif_index;
+ #ifdef __KAME__
+     *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] = htons(sin6.sin6_scope_id);
+     sin6.sin6_scope_id = 0;
+ #endif
      memcpy(walker, &sin6, sizeof (sin6));
      walker += step;
***************
*** 232,248 ****
    else
    {
!     // Sven-Ola: This looks really ugly (please compar to IPv4 above)
!     struct interface* iface = if_ifwithindex(nexthop->iif_index);
!     if (NULL == iface)
!     {
!       fprintf(stderr, "interface %s not found\n", if_ifwithindex_name(nexthop->iif_index));
!       return -1;
!     }
!     memcpy(&sin6.sin6_addr.s6_addr, &iface->int6_addr.sin6_addr.s6_addr,
!       sizeof(struct in6_addr));
  
      memcpy(walker, &sin6, sizeof (sin6));
      walker += step;
!     rtm->rtm_flags |= RTF_LLINFO;
    }
  
--- 240,256 ----
    else
    {
!     memcpy(&sin6.sin6_addr.s6_addr,  &rt->rt_dst.prefix.v6, sizeof(struct in6_addr));
!     memset(&sin6.sin6_addr.s6_addr, 0, 8);
!     sin6.sin6_addr.s6_addr[0] = 0xfe;
!     sin6.sin6_addr.s6_addr[1] = 0x80;
!     sin6.sin6_scope_id = nexthop->iif_index;
! #ifdef __KAME__
!     *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] = htons(sin6.sin6_scope_id);
!     sin6.sin6_scope_id = 0;
! #endif
  
      memcpy(walker, &sin6, sizeof (sin6));
      walker += step;
!     rtm->rtm_flags |= RTF_GATEWAY;
    }
  
***************
*** 255,274 ****
    }
  
-   if ((rtm->rtm_flags & RTF_GATEWAY) != 0)
-   {
-     strcpy(&sdl.sdl_data[0], if_ifwithindex_name(nexthop->iif_index));
-     sdl.sdl_nlen = (u_char)strlen((char*)&sdl.sdl_data[0]);
-     memcpy(walker, &sdl, sizeof (sdl));
-     walker += step_dl;
-     rtm->rtm_addrs |= RTA_IFP;
-   }
- 
    rtm->rtm_msglen = (unsigned short)(walker - buff);
  
    len = write(olsr_cnf->rts, buff, rtm->rtm_msglen);
! 
!   if (len < rtm->rtm_msglen)
      fprintf(stderr, "cannot write to routing socket: %s\n", strerror(errno));
  
    return 0;
  }
--- 263,301 ----
    }
  
    rtm->rtm_msglen = (unsigned short)(walker - buff);
  
    len = write(olsr_cnf->rts, buff, rtm->rtm_msglen);
!   if (len < 0 && !(errno == EEXIST || errno == ESRCH))
      fprintf(stderr, "cannot write to routing socket: %s\n", strerror(errno));
  
+   /* If we get an EEXIST error while adding, delete and retry. */
+   if (len < 0 && errno == EEXIST && rtm->rtm_type == RTM_ADD) {
+     struct rt_msghdr *drtm;
+     unsigned char dbuff[512];
+ 
+     memset(dbuff, 0, sizeof (dbuff));
+     drtm = (struct rt_msghdr *)dbuff;
+     drtm->rtm_version = RTM_VERSION;
+     drtm->rtm_type = RTM_DELETE;
+     drtm->rtm_addrs = RTA_DST;
+     drtm->rtm_index = 0;
+     drtm->rtm_flags = olsr_rt_flags(rt);
+     drtm->rtm_seq = ++seq;
+ 
+     walker = dbuff + sizeof (struct rt_msghdr);
+     memcpy(&sin6.sin6_addr.s6_addr, &rt->rt_dst.prefix.v6,
+ 	sizeof(struct in6_addr));
+     memcpy(walker, &sin6, sizeof (sin6));
+     walker += step;
+     drtm->rtm_msglen = (unsigned short)(walker - dbuff);
+     len = write(olsr_cnf->rts, dbuff, drtm->rtm_msglen);
+     if (len < 0)
+       fprintf(stderr, "cannot delete route: %s\n", strerror(errno));
+     rtm->rtm_seq = ++seq;
+     len = write(olsr_cnf->rts, buff, rtm->rtm_msglen);
+     if (len < 0)
+       fprintf(stderr, "still cannot add route: %s\n", strerror(errno));
+   }
+ 
    return 0;
  }





More information about the Olsr-cvs mailing list