[Olsr-cvs] olsrd-current/src olsr_cfg.h, 1.36, 1.37 net_olsr.h, 1.13, 1.14 net_olsr.c, 1.30, 1.31 lq_route.c, 1.55, 1.56 local_hna_set.h, 1.11, 1.12 local_hna_set.c, 1.14, 1.15 ipc_frontend.c, 1.36, 1.37 build_msg.c, 1.36, 1.37
Bernd Petrovitsch
(spam-protected)
Mon Nov 5 16:32:57 CET 2007
Update of /cvsroot/olsrd/olsrd-current/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7211/src
Modified Files:
olsr_cfg.h net_olsr.h net_olsr.c lq_route.c local_hna_set.h
local_hna_set.c ipc_frontend.c build_msg.c
Log Message:
Cleanup:
* Merged "struct hna4_entry" and "struct hna6_entry" into
"struct local_hna_entry" (as "struct hna_entry" is a different thing)
Both have almost the same data (IP address + netmask/prefix) so we use
the quite new "struct olsr_ip_prefix" to store it.
Also merged the "hna4" and "hna6" pointer in "struct olsr_config" -
look at the global "olsr_cnf->ip_version".
* const'ified here and there
* added a olsr_ip_prefix_to_string() function
Index: lq_route.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/lq_route.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -C2 -d -r1.55 -r1.56
*** lq_route.c 20 Oct 2007 15:16:32 -0000 1.55
--- lq_route.c 5 Nov 2007 15:32:55 -0000 1.56
***************
*** 134,138 ****
olsr_ip_to_string(&(vert->addr)),
vert->path_etx,
! olsr_ip_to_string(vert->next_hop ? &vert->next_hop->neighbor_iface_addr : NULL));
#endif
--- 134,138 ----
olsr_ip_to_string(&(vert->addr)),
vert->path_etx,
! vert->next_hop ? olsr_ip_to_string(&vert->next_hop->neighbor_iface_addr) : "-");
#endif
***************
*** 149,155 ****
olsr_spf_extract_best (struct avl_tree *tree)
{
! struct avl_node *node;
!
! node = avl_walk_first(tree);
return (node ? node->data : NULL);
--- 149,153 ----
olsr_spf_extract_best (struct avl_tree *tree)
{
! struct avl_node *node = avl_walk_first(tree);
return (node ? node->data : NULL);
***************
*** 164,168 ****
return "INF";
! snprintf(buff, 20, "%.6f", etx);
return buff;
}
--- 162,166 ----
return "INF";
! snprintf(buff, sizeof(buff), "%.6f", etx);
return buff;
}
Index: net_olsr.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/net_olsr.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** net_olsr.h 16 Sep 2007 21:20:16 -0000 1.13
--- net_olsr.h 5 Nov 2007 15:32:55 -0000 1.14
***************
*** 104,107 ****
--- 104,110 ----
olsr_ip_to_string(const union olsr_ip_addr *);
+ const char *
+ olsr_ip_prefix_to_string(const struct olsr_ip_prefix *prefix);
+
int
add_ptf(packet_transform_function);
Index: olsr_cfg.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/olsr_cfg.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** olsr_cfg.h 3 Nov 2007 23:21:27 -0000 1.36
--- olsr_cfg.h 5 Nov 2007 15:32:55 -0000 1.37
***************
*** 147,162 ****
};
! struct hna4_entry
! {
! union olsr_ip_addr net;
! union olsr_ip_addr netmask;
! struct hna4_entry *next;
! };
!
! struct hna6_entry
{
! union olsr_ip_addr net;
! olsr_u16_t prefix_len;
! struct hna6_entry *next;
};
--- 147,154 ----
};
! struct local_hna_entry
{
! struct olsr_ip_prefix net;
! struct local_hna_entry *next;
};
***************
*** 225,230 ****
float lq_dinter;
struct plugin_entry *plugins;
! struct hna4_entry *hna4_entries;
! struct hna6_entry *hna6_entries;
struct ipc_host *ipc_hosts;
struct ipc_net *ipc_nets;
--- 217,221 ----
float lq_dinter;
struct plugin_entry *plugins;
! struct local_hna_entry *hna_entries;
struct ipc_host *ipc_hosts;
struct ipc_net *ipc_nets;
Index: net_olsr.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/net_olsr.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** net_olsr.c 16 Sep 2007 21:20:16 -0000 1.30
--- net_olsr.c 5 Nov 2007 15:32:55 -0000 1.31
***************
*** 463,483 ****
*/
int
! olsr_prefix_to_netmask(union olsr_ip_addr *adr, olsr_u16_t prefix)
{
! int p, i;
! if(adr == NULL)
return 0;
! p = prefix;
! i = 0;
!
! memset(adr, 0, olsr_cnf->ipsize);
!
! for(;p > 0; p -= 8)
! {
! adr->v6.s6_addr[i] = (p < 8) ? 0xff ^ (0xff >> p) : 0xff;
! i++;
! }
#ifdef DEBUG
--- 463,483 ----
*/
int
! olsr_prefix_to_netmask(union olsr_ip_addr *adr, const olsr_u16_t prefix)
{
! int p;
! olsr_u8_t *a;
! if(adr == NULL) {
return 0;
+ }
! a = adr->v6.s6_addr;
! for (p = prefix; p > 8; p -= 8) {
! *a++ = 0xff;
! }
! *a++ = 0xff << p;
! while (a < adr->v6.s6_addr+olsr_cnf->ipsize) {
! *a++ = 0;
! }
#ifdef DEBUG
***************
*** 502,523 ****
olsr_u16_t prefix = 0;
unsigned int i;
! prefix = 0;
!
! for(i = 0; i < olsr_cnf->ipsize; i++)
! {
! if(adr->v6.s6_addr[i] == 0xff)
! {
! prefix += 8;
! }
! else
! {
! int tmp;
! for(tmp = adr->v6.s6_addr[i];
! tmp > 0;
! tmp = (tmp << 1) & 0xff)
! prefix++;
! }
! }
#ifdef DEBUG
--- 502,513 ----
olsr_u16_t prefix = 0;
unsigned int i;
+ olsr_u8_t tmp;
! for (i = 0; i < olsr_cnf->ipsize && adr->v6.s6_addr[i] == 0xff; i++) {
! prefix += 8;
! }
! for (tmp = adr->v6.s6_addr[i]; tmp > 0; tmp <<= 1) {
! prefix++;
! }
#ifdef DEBUG
***************
*** 562,566 ****
struct in_addr in;
in.s_addr=*address;
! return(inet_ntoa(in));
}
--- 552,556 ----
struct in_addr in;
in.s_addr=*address;
! return inet_ntoa(in);
}
***************
*** 583,592 ****
}
-
const char *
olsr_ip_to_string(const union olsr_ip_addr *addr)
{
static int idx = 0;
! static char buff[4][INET6_ADDRSTRLEN > INET_ADDRSTRLEN ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN];
const char *ret;
--- 573,581 ----
}
const char *
olsr_ip_to_string(const union olsr_ip_addr *addr)
{
static int idx = 0;
! static char buff[4][MAX(INET6_ADDRSTRLEN,INET_ADDRSTRLEN)];
const char *ret;
***************
*** 595,613 ****
}
! if(olsr_cnf->ip_version == AF_INET)
! {
! #if 0
! struct in_addr in;
! in.s_addr = addr->v4;
! ret = inet_ntop(AF_INET, &in, buff[idx], sizeof(buff[idx]));
! #else
! ret = inet_ntop(AF_INET, &addr->v4, buff[idx], sizeof(buff[idx]));
! #endif
! }
! else
! {
! /* IPv6 */
! ret = inet_ntop(AF_INET6, &addr->v6, buff[idx], sizeof(buff[idx]));
! }
idx = (idx + 1) & 3;
--- 584,593 ----
}
! if(olsr_cnf->ip_version == AF_INET) {
! ret = inet_ntop(AF_INET, &addr->v4, buff[idx], sizeof(buff[idx]));
! } else {
! /* IPv6 */
! ret = inet_ntop(AF_INET6, &addr->v6, buff[idx], sizeof(buff[idx]));
! }
idx = (idx + 1) & 3;
***************
*** 615,618 ****
--- 595,628 ----
}
+ const char *
+ olsr_ip_prefix_to_string(const struct olsr_ip_prefix *prefix)
+ {
+ /* We need for IPv6 an IP address + '/' + prefix and for IPv4 an IP address + '/' + a netmask */
+ static char buf[MAX(INET6_ADDRSTRLEN + 1 + 3, INET_ADDRSTRLEN + 1 + INET_ADDRSTRLEN)];
+ const char *rv;
+
+ if (prefix == NULL) {
+ return "null";
+ }
+
+ if(olsr_cnf->ip_version == AF_INET) {
+ int len;
+ union olsr_ip_addr netmask;
+ rv = inet_ntop(AF_INET, &prefix->prefix.v4, buf, sizeof(buf));
+ len = strlen(buf);
+ buf[len++] = '/';
+ olsr_prefix_to_netmask(&netmask, prefix->prefix_len);
+ inet_ntop(AF_INET, &netmask.v4, buf+len, sizeof(buf)-len);
+ } else {
+ int len;
+ /* IPv6 */
+ rv = inet_ntop(AF_INET6, &prefix->prefix.v6, buf, sizeof(buf));
+ len = strlen(buf);
+ buf[len++] = '/';
+ snprintf(buf+len, sizeof(buf)-len, "/%d", prefix->prefix_len);
+ }
+ return rv;
+ }
+
void
***************
*** 646,661 ****
const struct deny_address_entry *deny_entry = deny_entries;
! while(deny_entry)
! {
! if(COMP_IP(adr, &deny_entry->addr))
! {
! OLSR_PRINTF(1, "Validation of address %s failed!\n",
! olsr_ip_to_string(adr));
! return OLSR_FALSE;
! }
!
! deny_entry = deny_entry->next;
}
return OLSR_TRUE;
}
--- 656,669 ----
const struct deny_address_entry *deny_entry = deny_entries;
! while (deny_entry) {
! if (COMP_IP(adr, &deny_entry->addr)) {
! OLSR_PRINTF(1, "Validation of address %s failed!\n",
! olsr_ip_to_string(adr));
! return OLSR_FALSE;
}
+ deny_entry = deny_entry->next;
+ }
+
return OLSR_TRUE;
}
Index: local_hna_set.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/local_hna_set.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** local_hna_set.c 15 Oct 2007 20:58:33 -0000 1.14
--- local_hna_set.c 5 Nov 2007 15:32:55 -0000 1.15
***************
*** 47,60 ****
add_local_hna4_entry(const union olsr_ip_addr *net, const union olsr_ip_addr *mask)
{
! struct hna4_entry *new_entry;
!
! new_entry = olsr_malloc(sizeof(struct hna4_entry), "Add local HNA entry 4");
! new_entry->net.v4 = net->v4;
! new_entry->netmask.v4 = mask->v4;
/* Queue */
! new_entry->next = olsr_cnf->hna4_entries;
! olsr_cnf->hna4_entries = new_entry;
}
--- 47,58 ----
add_local_hna4_entry(const union olsr_ip_addr *net, const union olsr_ip_addr *mask)
{
! struct local_hna_entry *new_entry = olsr_malloc(sizeof(struct local_hna_entry), "Add local HNA entry 4");
! new_entry->net.prefix.v4 = net->v4;
! new_entry->net.prefix_len = olsr_netmask_to_prefix(mask);
/* Queue */
! new_entry->next = olsr_cnf->hna_entries;
! olsr_cnf->hna_entries = new_entry;
}
***************
*** 63,76 ****
add_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len)
{
! struct hna6_entry *new_entry;
!
! new_entry = olsr_malloc(sizeof(struct hna6_entry), "Add local HNA entry 6");
memcpy(&new_entry->net, net, sizeof(struct in6_addr));
! new_entry->prefix_len = prefix_len;
/* Queue */
! new_entry->next = olsr_cnf->hna6_entries;
! olsr_cnf->hna6_entries = new_entry;
}
--- 61,72 ----
add_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len)
{
! struct local_hna_entry *new_entry = olsr_malloc(sizeof(struct local_hna_entry), "Add local HNA entry 6");
memcpy(&new_entry->net, net, sizeof(struct in6_addr));
! new_entry->net.prefix_len = prefix_len;
/* Queue */
! new_entry->next = olsr_cnf->hna_entries;
! olsr_cnf->hna_entries = new_entry;
}
***************
*** 79,100 ****
remove_local_hna4_entry(const union olsr_ip_addr *net, const union olsr_ip_addr *mask)
{
! struct hna4_entry *h4 = olsr_cnf->hna4_entries, *h4prev = NULL;
! while(h4)
{
! if((net->v4 == h4->net.v4) &&
! (mask->v4 == h4->netmask.v4))
{
/* Dequeue */
! if(h4prev == NULL)
! olsr_cnf->hna4_entries = h4->next;
else
! h4prev->next = h4->next;
! free(h4);
return 1;
}
! h4prev = h4;
! h4 = h4->next;
}
--- 75,97 ----
remove_local_hna4_entry(const union olsr_ip_addr *net, const union olsr_ip_addr *mask)
{
! struct local_hna_entry *h = olsr_cnf->hna_entries, *prev = NULL;
! const olsr_u16_t prefix_len = olsr_netmask_to_prefix(mask);
! while(h)
{
! if((net->v4 == h->net.prefix.v4) &&
! (mask->v4 == prefix_len))
{
/* Dequeue */
! if(prev == NULL)
! olsr_cnf->hna_entries = h->next;
else
! prev->next = h->next;
! free(h);
return 1;
}
! prev = h;
! h = h->next;
}
***************
*** 107,144 ****
remove_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len)
{
! struct hna6_entry *h6, *h6prev = NULL;
! for(h6 = olsr_cnf->hna6_entries; h6; h6 = h6->next)
{
! if((memcmp(net, &h6->net, olsr_cnf->ipsize) == 0) &&
! (prefix_len == h6->prefix_len))
{
/* Dequeue */
! if(h6prev == NULL)
! olsr_cnf->hna6_entries = h6->next;
else
! h6prev->next = h6->next;
!
! free(h6);
return 1;
}
! h6prev = h6;
}
return 0;
}
! struct hna4_entry *
find_local_hna4_entry(const union olsr_ip_addr *net, const olsr_u32_t mask)
{
! struct hna4_entry *h4 = olsr_cnf->hna4_entries;
!
! while(h4)
{
! if((net->v4 == h4->net.v4) &&
! (mask == h4->netmask.v4))
{
! return h4;
}
! h4 = h4->next;
}
--- 104,142 ----
remove_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len)
{
! struct local_hna_entry *h = olsr_cnf->hna_entries, *prev = NULL;
! while (h)
{
! if((memcmp(net, &h->net.prefix, olsr_cnf->ipsize) == 0) &&
! (prefix_len == h->net.prefix_len))
{
/* Dequeue */
! if (prev == NULL)
! olsr_cnf->hna_entries = h->next;
else
! prev->next = h->next;
! free(h);
return 1;
}
! prev = h;
! h = h->next;
}
return 0;
}
! struct local_hna_entry *
find_local_hna4_entry(const union olsr_ip_addr *net, const olsr_u32_t mask)
{
! struct local_hna_entry *h = olsr_cnf->hna_entries;
! const union olsr_ip_addr ip_addr = { .v4 = mask };
! const olsr_u16_t prefix_len = olsr_netmask_to_prefix(&ip_addr);
! while(h)
{
! if((net->v4 == h->net.prefix.v4) &&
! (prefix_len == h->net.prefix_len))
{
! return h;
}
! h = h->next;
}
***************
*** 148,164 ****
! struct hna6_entry *
find_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len)
{
! struct hna6_entry *h6 = olsr_cnf->hna6_entries;
!
! while(h6)
{
! if((memcmp(net, &h6->net, olsr_cnf->ipsize) == 0) &&
! (prefix_len == h6->prefix_len))
{
! return h6;
}
! h6 = h6->next;
}
--- 146,161 ----
! struct local_hna_entry *
find_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len)
{
! struct local_hna_entry *h = olsr_cnf->hna_entries;
! while(h)
{
! if((memcmp(net, &h->net.prefix, olsr_cnf->ipsize) == 0) &&
! (prefix_len == h->net.prefix_len))
{
! return h;
}
! h = h->next;
}
***************
*** 174,181 ****
if(olsr_cnf->ip_version == AF_INET)
{
! struct hna4_entry *h4;
! for(h4 = olsr_cnf->hna4_entries; h4; h4 = h4->next)
{
! if(h4->netmask.v4 == 0 && h4->net.v4 == 0)
return 1;
}
--- 171,178 ----
if(olsr_cnf->ip_version == AF_INET)
{
! struct local_hna_entry *h;
! for(h = olsr_cnf->hna_entries; h != NULL; h = h->next)
{
! if(h->net.prefix_len == 0 && h->net.prefix.v4 == 0)
return 1;
}
Index: ipc_frontend.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/ipc_frontend.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** ipc_frontend.c 13 Oct 2007 12:31:04 -0000 1.36
--- ipc_frontend.c 5 Nov 2007 15:32:55 -0000 1.37
***************
*** 409,427 ****
/* HNAs */
! if(olsr_cnf->ip_version == AF_INET6)
! {
! if(olsr_cnf->hna6_entries == NULL)
! net_msg->hnas = 0;
! else
! net_msg->hnas = 1;
! }
!
! if(olsr_cnf->ip_version == AF_INET)
! {
! if(olsr_cnf->hna4_entries == NULL)
! net_msg->hnas = 0;
! else
! net_msg->hnas = 1;
! }
/* Different values */
--- 409,413 ----
/* HNAs */
! net_msg->hnas = olsr_cnf->hna_entries == NULL ? 0 : 1;
/* Different values */
***************
*** 434,441 ****
net_msg->topology_hold = 0;//htons((olsr_u16_t)topology_hold_time);
! if(olsr_cnf->ip_version == AF_INET)
! net_msg->ipv6 = 0;
! else
! net_msg->ipv6 = 1;
/* Main addr */
--- 420,424 ----
net_msg->topology_hold = 0;//htons((olsr_u16_t)topology_hold_time);
! net_msg->ipv6 = olsr_cnf->ip_version == AF_INET ? 0 : 1;
/* Main addr */
Index: build_msg.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/build_msg.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** build_msg.c 25 Apr 2007 22:08:07 -0000 1.36
--- build_msg.c 5 Nov 2007 15:32:55 -0000 1.37
***************
*** 1041,1045 ****
union olsr_message *m;
struct hnapair *pair;
! struct hna4_entry *h = olsr_cnf->hna4_entries;
/* No hna nets */
--- 1041,1045 ----
union olsr_message *m;
struct hnapair *pair;
! struct local_hna_entry *h = olsr_cnf->hna_entries;
/* No hna nets */
***************
*** 1074,1077 ****
--- 1074,1078 ----
while(h)
{
+ union olsr_ip_addr ip_addr;
if((curr_size + (2 * olsr_cnf->ipsize)) > remainsize)
{
***************
*** 1093,1102 ****
}
#ifdef DEBUG
! OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s/%s\n",
! olsr_ip_to_string(&h->net),
! olsr_ip_to_string(&h->netmask));
#endif
! COPY_IP(&pair->addr, &h->net);
! COPY_IP(&pair->netmask, &h->netmask);
pair++;
curr_size += (2 * olsr_cnf->ipsize);
--- 1094,1102 ----
}
#ifdef DEBUG
! OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s\n", olsr_ip_prefix_to_string(&h->net));
#endif
! COPY_IP(&pair->addr, &h->net.prefix);
! olsr_prefix_to_netmask(&ip_addr, h->net.prefix_len);
! pair->addr = ip_addr.v4;
pair++;
curr_size += (2 * olsr_cnf->ipsize);
***************
*** 1131,1135 ****
struct hnapair6 *pair6;
union olsr_ip_addr tmp_netmask;
! struct hna6_entry *h = olsr_cnf->hna6_entries;
/* No hna nets */
--- 1131,1135 ----
struct hnapair6 *pair6;
union olsr_ip_addr tmp_netmask;
! struct local_hna_entry *h = olsr_cnf->hna_entries;
/* No hna nets */
***************
*** 1183,1192 ****
}
#ifdef DEBUG
! OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s/%d\n",
! olsr_ip_to_string(&h->net),
! h->prefix_len);
#endif
! COPY_IP(&pair6->addr, &h->net);
! olsr_prefix_to_netmask(&tmp_netmask, h->prefix_len);
COPY_IP(&pair6->netmask, &tmp_netmask);
pair6++;
--- 1183,1190 ----
}
#ifdef DEBUG
! OLSR_PRINTF(BMSG_DBGLVL, "\tNet: %s\n", olsr_ip_prefix_to_string(&h->net));
#endif
! COPY_IP(&pair6->addr, &h->net.prefix);
! olsr_prefix_to_netmask(&tmp_netmask, h->net.prefix_len);
COPY_IP(&pair6->netmask, &tmp_netmask);
pair6++;
Index: local_hna_set.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/local_hna_set.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** local_hna_set.h 15 Oct 2007 20:58:33 -0000 1.11
--- local_hna_set.h 5 Nov 2007 15:32:55 -0000 1.12
***************
*** 59,66 ****
remove_local_hna6_entry(const union olsr_ip_addr *, const olsr_u16_t);
! struct hna4_entry *
find_local_hna4_entry(const union olsr_ip_addr *net, const olsr_u32_t mask);
! struct hna6_entry *
find_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len);
--- 59,66 ----
remove_local_hna6_entry(const union olsr_ip_addr *, const olsr_u16_t);
! struct local_hna_entry *
find_local_hna4_entry(const union olsr_ip_addr *net, const olsr_u32_t mask);
! struct local_hna_entry *
find_local_hna6_entry(const union olsr_ip_addr *net, const olsr_u16_t prefix_len);
More information about the Olsr-cvs
mailing list