[Olsr-cvs] olsrd-current/src/unix ifnet.c,1.52,1.53
Bernd Petrovitsch
(spam-protected)
Thu Nov 8 23:47:45 CET 2007
Update of /cvsroot/olsrd/olsrd-current/src/unix
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28726/src/unix
Modified Files:
ifnet.c
Log Message:
Another fat commit:
The main target was:
- Fixed the misleading definition of "v4" in "struct olsr_ip_addr" fom
"olsr_u32_t" (in network-byteorder!) to "struct in_addr". Lots of
temporary variables to call inet_ntoa()/inet_ptoa() vanished .....
- declare "int_addr", "int_netmask" and "int_broadaddr" in "struct interface"
as "struct sockaddr_in" since it is that what we actually want there (and
it is similar to the IPv6 code).
To get that thoroughly via compiler errors, we get:
- We have now ip4_to_string(), ip6_to_string() and olsr_ip_to_string()
to print a "struct in_addr", "struct in6_addr" and "union olsr_ip_addr"
into a string buffer.
Alas, this also annoyed me since ages:
- cleanup: olsr_ip_to_string() and similar non-reentrant functions now must
get a target buffer. To ease that, there is the "struct ipaddr_str"
which is large enough for all of them (read: for an IPv6 address). This
also removes the cyclic buffer there.
All of these function return a "const char *" which can be directly used
for printf(3) and friends.
And some cleanups:
- const'ified more functions
- converted the source to UTF-8.
- "struct sig_msg" uses an olsr_u8_t for a byte array (and not "char")
- force the few inline function to always be inlined.
- #ifdef the body of the olsr_print_hna_set() and olsr_print_neighbor_table()
if nothing is done
- use "inline_avl_comp_ipv4()" in "avl_comp_ipv4()"
- clean up the routes on more signals. Basically we want to do this on all
signals which terminate the program.
- killed a superflous global buffer in src/main.c
This version was breing since weeks and running for severa day in Vienna's
FunkFeuer net without any noticably problem!
Please report anything that broke!
Index: ifnet.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/src/unix/ifnet.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** ifnet.c 20 Oct 2007 12:59:08 -0000 1.52
--- ifnet.c 8 Nov 2007 22:47:42 -0000 1.53
***************
*** 210,214 ****
/* Check broadcast */
if ((olsr_cnf->ip_version == AF_INET) &&
! !iface->cnf->ipv4_broadcast.v4 && /* Skip if fixed bcast */
(!(ifp->int_flags & IFF_BROADCAST)))
{
--- 210,214 ----
/* Check broadcast */
if ((olsr_cnf->ip_version == AF_INET) &&
! !iface->cnf->ipv4_broadcast.v4.s_addr && /* Skip if fixed bcast */
(!(ifp->int_flags & IFF_BROADCAST)))
{
***************
*** 261,264 ****
--- 261,267 ----
if(olsr_cnf->ip_version == AF_INET6)
{
+ #if !defined(NODEBUG) && defined(DEBUG)
+ struct ipaddr_str buf;
+ #endif
/* Get interface address */
***************
*** 275,286 ****
#ifdef DEBUG
! OLSR_PRINTF(3, "\tAddress: %s\n", ip6_to_string(&tmp_saddr6.sin6_addr));
#endif
if(memcmp(&tmp_saddr6.sin6_addr, &ifp->int6_addr.sin6_addr, olsr_cnf->ipsize) != 0)
{
OLSR_PRINTF(1, "New IP address for %s:\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld: %s\n", ip6_to_string(&ifp->int6_addr.sin6_addr));
! OLSR_PRINTF(1, "\tNew: %s\n", ip6_to_string(&tmp_saddr6.sin6_addr));
/* Check main addr */
--- 278,292 ----
#ifdef DEBUG
! OLSR_PRINTF(3, "\tAddress: %s\n", ip6_to_string(&buf, &tmp_saddr6.sin6_addr));
#endif
if(memcmp(&tmp_saddr6.sin6_addr, &ifp->int6_addr.sin6_addr, olsr_cnf->ipsize) != 0)
{
+ #ifndef NODEBUG
+ struct ipaddr_str buf;
+ #endif
OLSR_PRINTF(1, "New IP address for %s:\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld: %s\n", ip6_to_string(&buf, &ifp->int6_addr.sin6_addr));
! OLSR_PRINTF(1, "\tNew: %s\n", ip6_to_string(&buf, &tmp_saddr6.sin6_addr));
/* Check main addr */
***************
*** 305,308 ****
--- 311,315 ----
/* IP version 4 */
{
+ struct ipaddr_str buf;
/* Check interface address (IPv4)*/
if(ioctl(olsr_cnf->ioctl_s, SIOCGIFADDR, &ifr) < 0)
***************
*** 313,317 ****
#ifdef DEBUG
! OLSR_PRINTF(3, "\tAddress:%s\n", sockaddr_to_string(&ifr.ifr_addr));
#endif
--- 320,324 ----
#ifdef DEBUG
! OLSR_PRINTF(3, "\tAddress:%s\n", sockaddr_to_string(&buf, &ifr.ifr_addr));
#endif
***************
*** 322,329 ****
/* New address */
OLSR_PRINTF(1, "IPv4 address changed for %s\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld:%s\n", sockaddr_to_string(&ifp->int_addr));
! OLSR_PRINTF(1, "\tNew:%s\n", sockaddr_to_string(&ifr.ifr_addr));
! ifp->int_addr = ifr.ifr_addr;
if(memcmp(&olsr_cnf->main_addr,
--- 329,336 ----
/* New address */
OLSR_PRINTF(1, "IPv4 address changed for %s\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld:%s\n", ip4_to_string(&buf, ifp->int_addr.sin_addr));
! OLSR_PRINTF(1, "\tNew:%s\n", sockaddr_to_string(&buf, &ifr.ifr_addr));
! ifp->int_addr = *(struct sockaddr_in *)&ifr.ifr_addr;
if(memcmp(&olsr_cnf->main_addr,
***************
*** 331,336 ****
olsr_cnf->ipsize) == 0)
{
! OLSR_PRINTF(1, "New main address: %s\n", sockaddr_to_string(&ifr.ifr_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", sockaddr_to_string(&ifr.ifr_addr));
memcpy(&olsr_cnf->main_addr,
&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr,
--- 338,343 ----
olsr_cnf->ipsize) == 0)
{
! OLSR_PRINTF(1, "New main address: %s\n", sockaddr_to_string(&buf, &ifr.ifr_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", sockaddr_to_string(&buf, &ifr.ifr_addr));
memcpy(&olsr_cnf->main_addr,
&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr,
***************
*** 353,357 ****
#ifdef DEBUG
! OLSR_PRINTF(3, "\tNetmask:%s\n", sockaddr_to_string(&ifr.ifr_netmask));
#endif
--- 360,364 ----
#ifdef DEBUG
! OLSR_PRINTF(3, "\tNetmask:%s\n", sockaddr_to_string(&buf, &ifr.ifr_netmask));
#endif
***************
*** 360,374 ****
olsr_cnf->ipsize) != 0)
{
/* New address */
OLSR_PRINTF(1, "IPv4 netmask changed for %s\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld:%s\n", sockaddr_to_string(&ifp->int_netmask));
! OLSR_PRINTF(1, "\tNew:%s\n", sockaddr_to_string(&ifr.ifr_netmask));
! ifp->int_netmask = ifr.ifr_netmask;
if_changes = 1;
}
! if(!iface->cnf->ipv4_broadcast.v4)
{
/* Check broadcast address */
--- 367,384 ----
olsr_cnf->ipsize) != 0)
{
+ #ifndef NODEBUG
+ struct ipaddr_str buf;
+ #endif
/* New address */
OLSR_PRINTF(1, "IPv4 netmask changed for %s\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld:%s\n", ip4_to_string(&buf, ifp->int_netmask.sin_addr));
! OLSR_PRINTF(1, "\tNew:%s\n", sockaddr_to_string(&buf, &ifr.ifr_netmask));
! ifp->int_netmask = *(struct sockaddr_in *)&ifr.ifr_netmask;
if_changes = 1;
}
! if(!iface->cnf->ipv4_broadcast.v4.s_addr)
{
/* Check broadcast address */
***************
*** 380,397 ****
#ifdef DEBUG
! OLSR_PRINTF(3, "\tBroadcast address:%s\n", sockaddr_to_string(&ifr.ifr_broadaddr));
#endif
! if(memcmp(&((struct sockaddr_in *)&ifp->int_broadaddr)->sin_addr.s_addr,
! &((struct sockaddr_in *)&ifr.ifr_broadaddr)->sin_addr.s_addr,
! olsr_cnf->ipsize) != 0)
{
!
/* New address */
OLSR_PRINTF(1, "IPv4 broadcast changed for %s\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld:%s\n", sockaddr_to_string(&ifp->int_broadaddr));
! OLSR_PRINTF(1, "\tNew:%s\n", sockaddr_to_string(&ifr.ifr_broadaddr));
! ifp->int_broadaddr = ifr.ifr_broadaddr;
if_changes = 1;
}
--- 390,407 ----
#ifdef DEBUG
! OLSR_PRINTF(3, "\tBroadcast address:%s\n", sockaddr_to_string(&buf, &ifr.ifr_broadaddr));
#endif
! if(ifp->int_broadaddr.sin_addr.s_addr != ((struct sockaddr_in *)&ifr.ifr_broadaddr)->sin_addr.s_addr)
{
! #ifndef NODEBUG
! struct ipaddr_str buf;
! #endif
/* New address */
OLSR_PRINTF(1, "IPv4 broadcast changed for %s\n", ifr.ifr_name);
! OLSR_PRINTF(1, "\tOld:%s\n", ip4_to_string(&buf, ifp->int_broadaddr.sin_addr));
! OLSR_PRINTF(1, "\tNew:%s\n", sockaddr_to_string(&buf, &ifr.ifr_broadaddr));
! ifp->int_broadaddr = *(struct sockaddr_in *)&ifr.ifr_broadaddr;
if_changes = 1;
}
***************
*** 436,440 ****
/* Check main addr */
! if(COMP_IP(&olsr_cnf->main_addr, &ifp->ip_addr))
{
if(ifnet == NULL)
--- 446,450 ----
/* Check main addr */
! if(ipequal(&olsr_cnf->main_addr, &ifp->ip_addr))
{
if(ifnet == NULL)
***************
*** 446,452 ****
else
{
! COPY_IP(&olsr_cnf->main_addr, &ifnet->ip_addr);
! OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&olsr_cnf->main_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&olsr_cnf->main_addr));
}
}
--- 456,464 ----
else
{
! struct ipaddr_str buf;
! //COPY_IP(&olsr_cnf->main_addr, &ifnet->ip_addr);
! olsr_cnf->main_addr = ifnet->ip_addr;
! OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
}
}
***************
*** 530,533 ****
--- 542,546 ----
union olsr_ip_addr null_addr;
olsr_u32_t addr[4];
+ struct ipaddr_str buf;
if(!iface->host_emul)
***************
*** 549,553 ****
OLSR_PRINTF(1, "Adding %s(host emulation):\n", ifp->int_name);
! OLSR_PRINTF(1, " Address:%s\n", olsr_ip_to_string(&iface->hemu_ip));
OLSR_PRINTF(1, " NB! This is a emulated interface\n that does not exist in the kernel!\n");
--- 562,566 ----
OLSR_PRINTF(1, "Adding %s(host emulation):\n", ifp->int_name);
! OLSR_PRINTF(1, " Address:%s\n", olsr_ip_to_string(&buf, &iface->hemu_ip));
OLSR_PRINTF(1, " NB! This is a emulated interface\n that does not exist in the kernel!\n");
***************
*** 557,565 ****
memset(&null_addr, 0, olsr_cnf->ipsize);
! if(COMP_IP(&null_addr, &olsr_cnf->main_addr))
{
! COPY_IP(&olsr_cnf->main_addr, &iface->hemu_ip);
! OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&olsr_cnf->main_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&olsr_cnf->main_addr));
}
--- 570,579 ----
memset(&null_addr, 0, olsr_cnf->ipsize);
! if(ipequal(&null_addr, &olsr_cnf->main_addr))
{
! //COPY_IP(&olsr_cnf->main_addr, &iface->hemu_ip);
! olsr_cnf->main_addr = iface->hemu_ip;
! OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
}
***************
*** 727,731 ****
*/
int
! chk_if_up(struct olsr_if *iface, int debuglvl)
{
struct interface ifs, *ifp;
--- 741,745 ----
*/
int
! chk_if_up(struct olsr_if *iface, int debuglvl __attribute__((unused)))
{
struct interface ifs, *ifp;
***************
*** 764,768 ****
/* Check broadcast */
if ((olsr_cnf->ip_version == AF_INET) &&
! !iface->cnf->ipv4_broadcast.v4 && /* Skip if fixed bcast */
(!(ifs.int_flags & IFF_BROADCAST)))
{
--- 778,782 ----
/* Check broadcast */
if ((olsr_cnf->ip_version == AF_INET) &&
! !iface->cnf->ipv4_broadcast.v4.s_addr && /* Skip if fixed bcast */
(!(ifs.int_flags & IFF_BROADCAST)))
{
***************
*** 793,797 ****
{
/* Get interface address */
!
if(get_ipv6_address(ifr.ifr_name, &ifs.int6_addr, iface->cnf->ipv6_addrtype) <= 0)
{
--- 807,813 ----
{
/* Get interface address */
! #ifndef NODEBUG
! struct ipaddr_str buf;
! #endif
if(get_ipv6_address(ifr.ifr_name, &ifs.int6_addr, iface->cnf->ipv6_addrtype) <= 0)
{
***************
*** 804,808 ****
}
! OLSR_PRINTF(debuglvl, "\tAddress: %s\n", ip6_to_string(&ifs.int6_addr.sin6_addr));
/* Multicast */
--- 820,824 ----
}
! OLSR_PRINTF(debuglvl, "\tAddress: %s\n", ip6_to_string(&buf, &ifs.int6_addr.sin6_addr));
/* Multicast */
***************
*** 819,823 ****
#endif
! OLSR_PRINTF(debuglvl, "\tMulticast: %s\n", ip6_to_string(&ifs.int6_multaddr.sin6_addr));
}
--- 835,839 ----
#endif
! OLSR_PRINTF(debuglvl, "\tMulticast: %s\n", ip6_to_string(&buf, &ifs.int6_multaddr.sin6_addr));
}
***************
*** 832,836 ****
}
! ifs.int_addr = ifr.ifr_addr;
/* Find netmask */
--- 848,852 ----
}
! ifs.int_addr = *(struct sockaddr_in *)&ifr.ifr_addr;
/* Find netmask */
***************
*** 842,849 ****
}
! ifs.int_netmask = ifr.ifr_netmask;
/* Find broadcast address */
! if(iface->cnf->ipv4_broadcast.v4)
{
/* Specified broadcast */
--- 858,865 ----
}
! ifs.int_netmask = *(struct sockaddr_in *)&ifr.ifr_netmask;
/* Find broadcast address */
! if(iface->cnf->ipv4_broadcast.v4.s_addr)
{
/* Specified broadcast */
***************
*** 862,866 ****
}
! ifs.int_broadaddr = ifr.ifr_broadaddr;
}
--- 878,882 ----
}
! ifs.int_broadaddr = *(struct sockaddr_in *)&ifr.ifr_broadaddr;
}
***************
*** 905,916 ****
if(olsr_cnf->ip_version == AF_INET)
{
! OLSR_PRINTF(1, "\tAddress:%s\n", sockaddr_to_string(&ifs.int_addr));
! OLSR_PRINTF(1, "\tNetmask:%s\n", sockaddr_to_string(&ifs.int_netmask));
! OLSR_PRINTF(1, "\tBroadcast address:%s\n", sockaddr_to_string(&ifs.int_broadaddr));
}
else
{
! OLSR_PRINTF(1, "\tAddress: %s\n", ip6_to_string(&ifs.int6_addr.sin6_addr));
! OLSR_PRINTF(1, "\tMulticast: %s\n", ip6_to_string(&ifs.int6_multaddr.sin6_addr));
}
--- 921,938 ----
if(olsr_cnf->ip_version == AF_INET)
{
! #ifndef NODEBUG
! struct ipaddr_str buf;
! #endif
! OLSR_PRINTF(1, "\tAddress:%s\n", ip4_to_string(&buf, ifs.int_addr.sin_addr));
! OLSR_PRINTF(1, "\tNetmask:%s\n", ip4_to_string(&buf, ifs.int_netmask.sin_addr));
! OLSR_PRINTF(1, "\tBroadcast address:%s\n", ip4_to_string(&buf, ifs.int_broadaddr.sin_addr));
}
else
{
! #ifndef NODEBUG
! struct ipaddr_str buf;
! #endif
! OLSR_PRINTF(1, "\tAddress: %s\n", ip6_to_string(&buf, &ifs.int6_addr.sin6_addr));
! OLSR_PRINTF(1, "\tMulticast: %s\n", ip6_to_string(&buf, &ifs.int6_multaddr.sin6_addr));
}
***************
*** 933,937 ****
{
/* IP version 4 */
! ifp->ip_addr.v4 = ((struct sockaddr_in *)&ifp->int_addr)->sin_addr.s_addr;
/*
*We create one socket for each interface and bind
--- 955,959 ----
{
/* IP version 4 */
! ifp->ip_addr.v4 = ifp->int_addr.sin_addr;
/*
*We create one socket for each interface and bind
***************
*** 954,959 ****
{
/* IP version 6 */
! memcpy(&ifp->ip_addr, &ifp->int6_addr.sin6_addr, olsr_cnf->ipsize);
!
/*
--- 976,980 ----
{
/* IP version 6 */
! ifp->ip_addr.v6 = ifp->int6_addr.sin6_addr;
/*
***************
*** 1006,1014 ****
*/
memset(&null_addr, 0, olsr_cnf->ipsize);
! if(COMP_IP(&null_addr, &olsr_cnf->main_addr))
{
! COPY_IP(&olsr_cnf->main_addr, &ifp->ip_addr);
! OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&olsr_cnf->main_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&olsr_cnf->main_addr));
}
--- 1027,1037 ----
*/
memset(&null_addr, 0, olsr_cnf->ipsize);
! if(ipequal(&null_addr, &olsr_cnf->main_addr))
{
! struct ipaddr_str buf;
! //COPY_IP(&olsr_cnf->main_addr, &ifp->ip_addr);
! olsr_cnf->main_addr = ifp->ip_addr;
! OLSR_PRINTF(1, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
! olsr_syslog(OLSR_LOG_INFO, "New main address: %s\n", olsr_ip_to_string(&buf, &olsr_cnf->main_addr));
}
***************
*** 1017,1048 ****
*/
! if (olsr_cnf->lq_level == 0)
! {
! olsr_register_scheduler_event(&generate_hello,
! ifp,
! iface->cnf->hello_params.emission_interval,
! 0,
! NULL);
! olsr_register_scheduler_event(&generate_tc,
! ifp,
! iface->cnf->tc_params.emission_interval,
! 0,
! NULL);
! }
!
! else
! {
! olsr_register_scheduler_event(&olsr_output_lq_hello,
! ifp,
! iface->cnf->hello_params.emission_interval,
! 0,
! NULL);
! olsr_register_scheduler_event(&olsr_output_lq_tc,
! ifp,
! iface->cnf->tc_params.emission_interval,
! 0,
! NULL);
! }
!
olsr_register_scheduler_event(&generate_mid,
ifp,
--- 1040,1053 ----
*/
! olsr_register_scheduler_event(olsr_cnf->lq_level == 0 ? &generate_hello : &olsr_output_lq_hello,
! ifp,
! iface->cnf->hello_params.emission_interval,
! 0,
! NULL);
! olsr_register_scheduler_event(olsr_cnf->lq_level == 0 ? &generate_tc : &olsr_output_lq_tc,
! ifp,
! iface->cnf->tc_params.emission_interval,
! 0,
! NULL);
olsr_register_scheduler_event(&generate_mid,
ifp,
***************
*** 1059,1069 ****
if((olsr_cnf->max_jitter == 0) ||
! ((iface->cnf->hello_params.emission_interval / 4) < olsr_cnf->max_jitter))
olsr_cnf->max_jitter = iface->cnf->hello_params.emission_interval / 4;
/* Recalculate max topology hold time */
! if(olsr_cnf->max_tc_vtime < iface->cnf->tc_params.emission_interval)
olsr_cnf->max_tc_vtime = iface->cnf->tc_params.emission_interval;
!
ifp->hello_etime = iface->cnf->hello_params.emission_interval;
ifp->valtimes.hello = double_to_me(iface->cnf->hello_params.validity_time);
--- 1064,1075 ----
if((olsr_cnf->max_jitter == 0) ||
! ((iface->cnf->hello_params.emission_interval / 4) < olsr_cnf->max_jitter)) {
olsr_cnf->max_jitter = iface->cnf->hello_params.emission_interval / 4;
+ }
/* Recalculate max topology hold time */
! if(olsr_cnf->max_tc_vtime < iface->cnf->tc_params.emission_interval) {
olsr_cnf->max_tc_vtime = iface->cnf->tc_params.emission_interval;
! }
ifp->hello_etime = iface->cnf->hello_params.emission_interval;
ifp->valtimes.hello = double_to_me(iface->cnf->hello_params.validity_time);
More information about the Olsr-cvs
mailing list