[Olsr-cvs] olsrd-current/src defs.h, 1.53, 1.54 interfaces.h, 1.34, 1.35 net_olsr.c, 1.16, 1.17
Bernd Petrovitsch
(spam-protected)
Thu Nov 16 00:08:01 CET 2006
Update of /cvsroot/olsrd/olsrd-current/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv19540/src
Modified Files:
defs.h interfaces.h net_olsr.c
Log Message:
I removed the hardcoded (and BTW never checked) limit on 16 interfaces:
We do this by adding the "struct netbuf" to the "struct interface" because
- we avoid maintaining a separate array of pointers and malloc(3)ed struct's.
- we avoid therefore lots of malloc(3) and free(3).
- we need such a thing anyway for each interface, so why not put it in there
(and libnet_ctx is also there).
- we do not longer neeed the interface-index as a separate field.
Does anyone know if the MTU of an interface may chnage (and if yes, when)?
Otherwise we could get rid of another field in that struct (and a few lines
of code).
I compile-tested with `make build_all USE_LIBNET=1` but didn't run it.
Downside: One must initialize this struct (or at least the pointer to the
actual buffer). Therefore the one line change in src/unix/ifnet.c.
Therefore I broke very probably the Windows port and I can' figure out
if and where to add such an equivalent thing.
Other changes:
- The libnet_ctx field in struct interface is also in a
#ifdef USE_LIBNET ... #endif section.
Index: defs.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/defs.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** defs.h 1 Nov 2006 09:20:13 -0000 1.53
--- defs.h 15 Nov 2006 23:07:59 -0000 1.54
***************
*** 72,76 ****
#define UDP_IPV4_HDRSIZE 28
#define UDP_IPV6_HDRSIZE 48
- #define MAX_IFS 16
#define MIN_PACKET_SIZE(ver) (int)(sizeof(olsr_u8_t) * ((ver == AF_INET) ? 4 : 7))
--- 72,75 ----
Index: net_olsr.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/net_olsr.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** net_olsr.c 15 Nov 2006 21:13:52 -0000 1.16
--- net_olsr.c 15 Nov 2006 23:07:59 -0000 1.17
***************
*** 73,88 ****
- /* Output buffer structure */
-
- struct olsr_netbuf
- {
- char *buff; /* Pointer to the allocated buffer */
- int if_index;
- int bufsize; /* Size of the buffer */
- int maxsize; /* Max bytes of payload that can be added to the buffer */
- int pending; /* How much data is currently pending in the buffer */
- int reserved; /* Plugins can reserve space in buffers */
- };
-
/* Packet transform functions */
--- 73,76 ----
***************
*** 95,100 ****
static struct ptf *ptf_list;
- static struct olsr_netbuf *netbufs[MAX_IFS];
-
static char ipv6_buf[100]; /* for address coversion */
--- 83,86 ----
***************
*** 187,213 ****
net_add_buffer(struct interface *ifp)
{
! struct olsr_netbuf *new_buf;
!
! /* If a buffer already exists for this interface back off */
! if(netbufs[ifp->if_nr])
! return -1;
!
! new_buf = olsr_malloc(sizeof(struct olsr_netbuf), "add_netbuff1");
! new_buf->buff = olsr_malloc(ifp->int_mtu, "add_netbuff2");
/* Fill struct */
! new_buf->bufsize = ifp->int_mtu;
! new_buf->if_index = ifp->if_nr;
! new_buf->maxsize = ifp->int_mtu - OLSR_HEADERSIZE;
!
! new_buf->pending = 0;
! new_buf->reserved = 0;
! netbufs[ifp->if_nr] = new_buf;
return 0;
}
-
/**
* Remove a outputbuffer. Frees the allocated memory.
--- 173,198 ----
net_add_buffer(struct interface *ifp)
{
! /* Can the interfaces MTU actually change? If not, we can elimiate
! * the "bufsize" field in "struct olsr_netbuf".
! */
! if (ifp->netbuf.bufsize != ifp->int_mtu && ifp->netbuf.buff != NULL) {
! free(ifp->netbuf.buff);
! ifp->netbuf.buff = NULL;
! }
!
! if (ifp->netbuf.buff == NULL) {
! ifp->netbuf.buff = olsr_malloc(ifp->int_mtu, "add_netbuff");
! }
/* Fill struct */
! ifp->netbuf.bufsize = ifp->int_mtu;
! ifp->netbuf.maxsize = ifp->int_mtu - OLSR_HEADERSIZE;
! ifp->netbuf.pending = 0;
! ifp->netbuf.reserved = 0;
return 0;
}
/**
* Remove a outputbuffer. Frees the allocated memory.
***************
*** 221,236 ****
net_remove_buffer(struct interface *ifp)
{
-
- /* If a buffer does no exist for this interface back off */
- if(!netbufs[ifp->if_nr])
- return -1;
-
/* Flush pending data */
! if(netbufs[ifp->if_nr]->pending)
net_output(ifp);
! free(netbufs[ifp->if_nr]->buff);
! free(netbufs[ifp->if_nr]);
! netbufs[ifp->if_nr] = NULL;
return 0;
--- 206,215 ----
net_remove_buffer(struct interface *ifp)
{
/* Flush pending data */
! if(ifp->netbuf.pending)
net_output(ifp);
! free(ifp->netbuf.buff);
! ifp->netbuf.buff = NULL;
return 0;
***************
*** 238,242 ****
-
/**
* Reserve space in a outputbuffer. This should only be needed
--- 217,220 ----
***************
*** 256,264 ****
net_reserve_bufspace(struct interface *ifp, int size)
{
! if((!netbufs[ifp->if_nr]) || (size > netbufs[ifp->if_nr]->maxsize))
return -1;
! netbufs[ifp->if_nr]->reserved = size;
! netbufs[ifp->if_nr]->maxsize -= size;
return 0;
--- 234,242 ----
net_reserve_bufspace(struct interface *ifp, int size)
{
! if(size > ifp->netbuf.maxsize)
return -1;
! ifp->netbuf.reserved = size;
! ifp->netbuf.maxsize -= size;
return 0;
***************
*** 276,283 ****
net_output_pending(struct interface *ifp)
{
! if(!netbufs[ifp->if_nr])
! return -1;
!
! return netbufs[ifp->if_nr]->pending;
}
--- 254,258 ----
net_output_pending(struct interface *ifp)
{
! return ifp->netbuf.pending;
}
***************
*** 298,310 ****
net_outbuffer_push(struct interface *ifp, olsr_u8_t *data, olsr_u16_t size)
{
!
! if(!netbufs[ifp->if_nr])
! return -1;
!
! if((netbufs[ifp->if_nr]->pending + size) > netbufs[ifp->if_nr]->maxsize)
return 0;
! memcpy(&netbufs[ifp->if_nr]->buff[netbufs[ifp->if_nr]->pending + OLSR_HEADERSIZE], data, size);
! netbufs[ifp->if_nr]->pending += size;
return size;
--- 273,281 ----
net_outbuffer_push(struct interface *ifp, olsr_u8_t *data, olsr_u16_t size)
{
! if((ifp->netbuf.pending + size) > ifp->netbuf.maxsize)
return 0;
! memcpy(&ifp->netbuf.buff[ifp->netbuf.pending + OLSR_HEADERSIZE], data, size);
! ifp->netbuf.pending += size;
return size;
***************
*** 326,338 ****
net_outbuffer_push_reserved(struct interface *ifp, olsr_u8_t *data, olsr_u16_t size)
{
!
! if(!netbufs[ifp->if_nr])
! return -1;
!
! if((netbufs[ifp->if_nr]->pending + size) > (netbufs[ifp->if_nr]->maxsize + netbufs[ifp->if_nr]->reserved))
return 0;
! memcpy(&netbufs[ifp->if_nr]->buff[netbufs[ifp->if_nr]->pending + OLSR_HEADERSIZE], data, size);
! netbufs[ifp->if_nr]->pending += size;
return size;
--- 297,305 ----
net_outbuffer_push_reserved(struct interface *ifp, olsr_u8_t *data, olsr_u16_t size)
{
! if((ifp->netbuf.pending + size) > (ifp->netbuf.maxsize + ifp->netbuf.reserved))
return 0;
! memcpy(&ifp->netbuf.buff[ifp->netbuf.pending + OLSR_HEADERSIZE], data, size);
! ifp->netbuf.pending += size;
return size;
***************
*** 350,357 ****
net_outbuffer_bytes_left(struct interface *ifp)
{
! if(!netbufs[ifp->if_nr])
! return 0;
!
! return netbufs[ifp->if_nr]->maxsize - netbufs[ifp->if_nr]->pending;
}
--- 317,321 ----
net_outbuffer_bytes_left(struct interface *ifp)
{
! return ifp->netbuf.maxsize - ifp->netbuf.pending;
}
***************
*** 457,462 ****
int
net_output(struct interface *ifp)
- #ifdef USE_LIBNET
{
struct ptf *tmp_ptf_list;
union olsr_packet *outmsg;
--- 421,426 ----
int
net_output(struct interface *ifp)
{
+ #ifdef USE_LIBNET
struct ptf *tmp_ptf_list;
union olsr_packet *outmsg;
***************
*** 464,484 ****
libnet_ptag_t udp_ptag = 0, ip_ptag = 0;
! if(!netbufs[ifp->if_nr])
! return -1;
!
! if(!netbufs[ifp->if_nr]->pending)
return 0;
assert(ifp->libnet_ctx != NULL);
! netbufs[ifp->if_nr]->pending += OLSR_HEADERSIZE;
! retval = netbufs[ifp->if_nr]->pending;
! outmsg = (union olsr_packet *)netbufs[ifp->if_nr]->buff;
/* Add the Packet seqno */
outmsg->v4.olsr_seqno = htons(ifp->olsr_seqnum++);
/* Set the packetlength */
! outmsg->v4.olsr_packlen = htons(netbufs[ifp->if_nr]->pending);
/*
--- 428,445 ----
libnet_ptag_t udp_ptag = 0, ip_ptag = 0;
! if(!ifp->netbuf.pending)
return 0;
assert(ifp->libnet_ctx != NULL);
! ifp->netbuf.pending += OLSR_HEADERSIZE;
! retval = ifp->netbuf.pending;
! outmsg = (union olsr_packet *)ifp->netbuf.buff;
/* Add the Packet seqno */
outmsg->v4.olsr_seqno = htons(ifp->olsr_seqnum++);
/* Set the packetlength */
! outmsg->v4.olsr_packlen = htons(ifp->netbuf.pending);
/*
***************
*** 488,492 ****
while(tmp_ptf_list != NULL)
{
! tmp_ptf_list->function(netbufs[ifp->if_nr]->buff, &netbufs[ifp->if_nr]->pending);
tmp_ptf_list = tmp_ptf_list->next;
}
--- 449,453 ----
while(tmp_ptf_list != NULL)
{
! tmp_ptf_list->function(ifp->netbuf.buff, &ifp->netbuf.pending);
tmp_ptf_list = tmp_ptf_list->next;
}
***************
*** 497,512 ****
*/
if(disp_pack_out)
! print_olsr_serialized_packet(stdout, (union olsr_packet *)netbufs[ifp->if_nr]->buff,
! netbufs[ifp->if_nr]->pending, &ifp->ip_addr);
printf("LIBNET TX %d bytes on %s\n",
! netbufs[ifp->if_nr]->pending, ifp->int_name);
udp_ptag = libnet_build_udp(OLSRPORT,
OLSRPORT,
! LIBNET_UDP_H + netbufs[ifp->if_nr]->pending,
0,
! (u_int8_t *)netbufs[ifp->if_nr]->buff,
! netbufs[ifp->if_nr]->pending,
ifp->libnet_ctx,
0);
--- 458,473 ----
*/
if(disp_pack_out)
! print_olsr_serialized_packet(stdout, (union olsr_packet *)ifp->netbuf.buff,
! ifp->netbuf.pending, &ifp->ip_addr);
printf("LIBNET TX %d bytes on %s\n",
! ifp->netbuf.pending, ifp->int_name);
udp_ptag = libnet_build_udp(OLSRPORT,
OLSRPORT,
! LIBNET_UDP_H + ifp->netbuf.pending,
0,
! (u_int8_t *)ifp->netbuf.buff,
! ifp->netbuf.pending,
ifp->libnet_ctx,
0);
***************
*** 515,519 ****
{
OLSR_PRINTF (1, "libnet UDP header: %s\n", libnet_geterror (ifp->libnet_ctx))
! netbufs[ifp->if_nr]->pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
--- 476,480 ----
{
OLSR_PRINTF (1, "libnet UDP header: %s\n", libnet_geterror (ifp->libnet_ctx))
! ifp->netbuf.pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
***************
*** 523,527 ****
{
/* IP version 4 */
! ip_ptag = libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_UDP_H + netbufs[ifp->if_nr]->pending,
olsr_cnf->tos,
ifp->olsr_seqnum,
--- 484,488 ----
{
/* IP version 4 */
! ip_ptag = libnet_build_ipv4(LIBNET_IPV4_H + LIBNET_UDP_H + ifp->netbuf.pending,
olsr_cnf->tos,
ifp->olsr_seqnum,
***************
*** 539,543 ****
{
OLSR_PRINTF (1, "libnet IP header: %s\n", libnet_geterror (ifp->libnet_ctx))
! netbufs[ifp->if_nr]->pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
--- 500,504 ----
{
OLSR_PRINTF (1, "libnet IP header: %s\n", libnet_geterror (ifp->libnet_ctx))
! ifp->netbuf.pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
***************
*** 570,577 ****
printf("Build IPv6 size: %d\n",
! LIBNET_IPV6_H + LIBNET_UDP_H + netbufs[ifp->if_nr]->pending);
ip_ptag = libnet_build_ipv6(0, /* Traffic class */
0, /* Flow label */
! LIBNET_IPV6_H + LIBNET_UDP_H + netbufs[ifp->if_nr]->pending,
IPPROTO_UDP, /* Next Header */
64, /* Hop Limit */
--- 531,538 ----
printf("Build IPv6 size: %d\n",
! LIBNET_IPV6_H + LIBNET_UDP_H + ifp->netbuf.pending);
ip_ptag = libnet_build_ipv6(0, /* Traffic class */
0, /* Flow label */
! LIBNET_IPV6_H + LIBNET_UDP_H + ifp->netbuf.pending,
IPPROTO_UDP, /* Next Header */
64, /* Hop Limit */
***************
*** 586,590 ****
{
OLSR_PRINTF (1, "libnet IP header: %s\n", libnet_geterror (ifp->libnet_ctx))
! netbufs[ifp->if_nr]->pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
--- 547,551 ----
{
OLSR_PRINTF (1, "libnet IP header: %s\n", libnet_geterror (ifp->libnet_ctx))
! ifp->netbuf.pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
***************
*** 595,599 ****
{
libnet_ptag_t ether_tag = 0;
! unsigned char enet_broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
/* We should add layer2 as well later */
--- 556,560 ----
{
libnet_ptag_t ether_tag = 0;
! static const unsigned char enet_broadcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
/* We should add layer2 as well later */
***************
*** 608,612 ****
{
OLSR_PRINTF (1, "libnet ethernet header: %s\n", libnet_geterror (ifp->libnet_ctx))
! netbufs[ifp->if_nr]->pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
--- 569,573 ----
{
OLSR_PRINTF (1, "libnet ethernet header: %s\n", libnet_geterror (ifp->libnet_ctx))
! ifp->netbuf.pending = 0;
libnet_clear_packet(ifp->libnet_ctx);
return -1;
***************
*** 623,638 ****
libnet_clear_packet(ifp->libnet_ctx);
! netbufs[ifp->if_nr]->pending = 0;
!
! // if we've just transmitted a TC message, let Dijkstra use the current
! // link qualities for the links to our neighbours
!
! olsr_update_dijkstra_link_qualities();
! lq_tc_pending = OLSR_FALSE;
!
! return retval;
! }
#else
- {
struct sockaddr_in *sin;
struct sockaddr_in dst;
--- 584,589 ----
libnet_clear_packet(ifp->libnet_ctx);
! ifp->netbuf.pending = 0;
#else
struct sockaddr_in *sin;
struct sockaddr_in dst;
***************
*** 646,664 ****
sin6 = NULL;
! if(!netbufs[ifp->if_nr])
! return -1;
!
! if(!netbufs[ifp->if_nr]->pending)
return 0;
! netbufs[ifp->if_nr]->pending += OLSR_HEADERSIZE;
! retval = netbufs[ifp->if_nr]->pending;
! outmsg = (union olsr_packet *)netbufs[ifp->if_nr]->buff;
/* Add the Packet seqno */
outmsg->v4.olsr_seqno = htons(ifp->olsr_seqnum++);
/* Set the packetlength */
! outmsg->v4.olsr_packlen = htons(netbufs[ifp->if_nr]->pending);
if(olsr_cnf->ip_version == AF_INET)
--- 597,612 ----
sin6 = NULL;
! if(!ifp->netbuf.pending)
return 0;
! ifp->netbuf.pending += OLSR_HEADERSIZE;
! retval = ifp->netbuf.pending;
! outmsg = (union olsr_packet *)ifp->netbuf.buff;
/* Add the Packet seqno */
outmsg->v4.olsr_seqno = htons(ifp->olsr_seqnum++);
/* Set the packetlength */
! outmsg->v4.olsr_packlen = htons(ifp->netbuf.pending);
if(olsr_cnf->ip_version == AF_INET)
***************
*** 689,693 ****
while(tmp_ptf_list != NULL)
{
! tmp_ptf_list->function(netbufs[ifp->if_nr]->buff, &netbufs[ifp->if_nr]->pending);
tmp_ptf_list = tmp_ptf_list->next;
}
--- 637,641 ----
while(tmp_ptf_list != NULL)
{
! tmp_ptf_list->function(ifp->netbuf.buff, &ifp->netbuf.pending);
tmp_ptf_list = tmp_ptf_list->next;
}
***************
*** 698,703 ****
*/
if(disp_pack_out)
! print_olsr_serialized_packet(stdout, (union olsr_packet *)netbufs[ifp->if_nr]->buff,
! netbufs[ifp->if_nr]->pending, &ifp->ip_addr);
if(olsr_cnf->ip_version == AF_INET)
--- 646,651 ----
*/
if(disp_pack_out)
! print_olsr_serialized_packet(stdout, (union olsr_packet *)ifp->netbuf.buff,
! ifp->netbuf.pending, &ifp->ip_addr);
if(olsr_cnf->ip_version == AF_INET)
***************
*** 705,710 ****
/* IP version 4 */
if(olsr_sendto(ifp->olsr_socket,
! netbufs[ifp->if_nr]->buff,
! netbufs[ifp->if_nr]->pending,
MSG_DONTROUTE,
(struct sockaddr *)sin,
--- 653,658 ----
/* IP version 4 */
if(olsr_sendto(ifp->olsr_socket,
! ifp->netbuf.buff,
! ifp->netbuf.pending,
MSG_DONTROUTE,
(struct sockaddr *)sin,
***************
*** 721,726 ****
/* IP version 6 */
if(olsr_sendto(ifp->olsr_socket,
! netbufs[ifp->if_nr]->buff,
! netbufs[ifp->if_nr]->pending,
MSG_DONTROUTE,
(struct sockaddr *)sin6,
--- 669,674 ----
/* IP version 6 */
if(olsr_sendto(ifp->olsr_socket,
! ifp->netbuf.buff,
! ifp->netbuf.pending,
MSG_DONTROUTE,
(struct sockaddr *)sin6,
***************
*** 732,742 ****
fprintf(stderr, "Socket: %d interface: %d\n", ifp->olsr_socket, ifp->if_nr);
fprintf(stderr, "To: %s (size: %d)\n", ip6_to_string(&sin6->sin6_addr), (int)sizeof(*sin6));
! fprintf(stderr, "Outputsize: %d\n", netbufs[ifp->if_nr]->pending);
retval = -1;
}
}
! netbufs[ifp->if_nr]->pending = 0;
!
// if we've just transmitted a TC message, let Dijkstra use the current
// link qualities for the links to our neighbours
--- 680,690 ----
fprintf(stderr, "Socket: %d interface: %d\n", ifp->olsr_socket, ifp->if_nr);
fprintf(stderr, "To: %s (size: %d)\n", ip6_to_string(&sin6->sin6_addr), (int)sizeof(*sin6));
! fprintf(stderr, "Outputsize: %d\n", ifp->netbuf.pending);
retval = -1;
}
}
! ifp->netbuf.pending = 0;
! #endif
// if we've just transmitted a TC message, let Dijkstra use the current
// link qualities for the links to our neighbours
***************
*** 747,751 ****
return retval;
}
- #endif
--- 695,698 ----
Index: interfaces.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/interfaces.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** interfaces.h 11 Oct 2006 20:58:45 -0000 1.34
--- interfaces.h 15 Nov 2006 23:07:59 -0000 1.35
***************
*** 108,111 ****
--- 108,123 ----
};
+ /* Output buffer structure. This should actually be in net_olsr.h but we have circular references then.
+ */
+ struct olsr_netbuf
+ {
+ olsr_u8_t *buff;/* Pointer to the allocated buffer */
+ int bufsize; /* Size of the buffer */
+ int maxsize; /* Max bytes of payload that can be added to the buffer */
+ int pending; /* How much data is currently pending in the buffer */
+ int reserved; /* Plugins can reserve space in buffers */
+ };
+
+
/**
*A struct containing all necessary information about each
***************
*** 139,143 ****
--- 151,158 ----
clock_t fwdtimer; /* Timeout for OLSR forwarding on this if */
+ #ifdef USE_LIBNET
void *libnet_ctx; /* libnet context(void to avoid dependency */
+ #endif
+ struct olsr_netbuf netbuf; /* the buffer to construct the packet data */
struct if_gen_property *gen_properties;/* Generic interface properties */
More information about the Olsr-cvs
mailing list