Define logger(), cleans up source code and allows us to write log entries
[tinc] / src / route.c
index b6ec0dc..1fd1d8e 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: route.c,v 1.1.2.53 2003/07/06 17:49:49 guus Exp $
+    $Id: route.c,v 1.1.2.54 2003/07/06 22:11:33 guus Exp $
 */
 
 #include "config.h"
@@ -45,7 +45,6 @@
 #include <netinet/if_ether.h>
 #include <utils.h>
 #include <xalloc.h>
-#include <syslog.h>
 #include <string.h>
 #ifdef HAVE_INTTYPES_H
 #include <inttypes.h>
@@ -59,6 +58,7 @@
 #include "route.h"
 #include "protocol.h"
 #include "device.h"
+#include "logger.h"
 
 #include "system.h"
 
@@ -130,8 +130,7 @@ void learn_mac(mac_t *address)
        /* If we don't know this MAC address yet, store it */
 
        if(!subnet || subnet->owner != myself) {
-               if(debug_lvl >= DEBUG_TRAFFIC)
-                       syslog(LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
+               logger(DEBUG_TRAFFIC, LOG_INFO, _("Learned new MAC address %hx:%hx:%hx:%hx:%hx:%hx"),
                                   address->x[0], address->x[1], address->x[2], address->x[3],
                                   address->x[4], address->x[5]);
 
@@ -164,8 +163,7 @@ void age_mac(void)
                next = node->next;
                s = (subnet_t *) node->data;
                if(s->type == SUBNET_MAC && s->net.mac.lastseen && s->net.mac.lastseen + macexpire < now) {
-                       if(debug_lvl >= DEBUG_TRAFFIC)
-                               syslog(LOG_INFO, _("MAC address %hx:%hx:%hx:%hx:%hx:%hx expired"),
+                       logger(DEBUG_TRAFFIC, LOG_INFO, _("MAC address %hx:%hx:%hx:%hx:%hx:%hx expired"),
                                           s->net.mac.address.x[0], s->net.mac.address.x[1],
                                           s->net.mac.address.x[2], s->net.mac.address.x[3],
                                           s->net.mac.address.x[4], s->net.mac.address.x[5]);
@@ -274,11 +272,9 @@ node_t *route_ipv4(vpn_packet_t *packet)
        subnet = lookup_subnet_ipv4((ipv4_t *) & packet->data[30]);
 
        if(!subnet) {
-               if(debug_lvl >= DEBUG_TRAFFIC) {
-                       syslog(LOG_WARNING, _("Cannot route packet: unknown IPv4 destination address %d.%d.%d.%d"),
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown IPv4 destination address %d.%d.%d.%d"),
                                   packet->data[30], packet->data[31], packet->data[32],
                                   packet->data[33]);
-               }
 
                route_ipv4_unreachable(packet, ICMP_NET_UNKNOWN);
                return NULL;
@@ -371,8 +367,7 @@ node_t *route_ipv6(vpn_packet_t *packet)
        subnet = lookup_subnet_ipv6((ipv6_t *) & packet->data[38]);
 
        if(!subnet) {
-               if(debug_lvl >= DEBUG_TRAFFIC) {
-                       syslog(LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown IPv6 destination address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
                                   ntohs(*(uint16_t *) & packet->data[38]),
                                   ntohs(*(uint16_t *) & packet->data[40]),
                                   ntohs(*(uint16_t *) & packet->data[42]),
@@ -381,7 +376,6 @@ node_t *route_ipv6(vpn_packet_t *packet)
                                   ntohs(*(uint16_t *) & packet->data[48]),
                                   ntohs(*(uint16_t *) & packet->data[50]),
                                   ntohs(*(uint16_t *) & packet->data[52]));
-               }
 #ifdef HAVE_NETINET_IP6_H
                route_ipv6_unreachable(packet, ICMP6_DST_UNREACH_ADDR);
 #endif
@@ -431,9 +425,7 @@ void route_neighborsol(vpn_packet_t *packet)
 
        if(ns->nd_ns_hdr.icmp6_type != ND_NEIGHBOR_SOLICIT ||
           opt->nd_opt_type != ND_OPT_SOURCE_LINKADDR) {
-               if(debug_lvl > DEBUG_TRAFFIC) {
-                       syslog(LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
-               }
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: received unknown type neighbor solicitation request"));
                return;
        }
 
@@ -450,8 +442,7 @@ void route_neighborsol(vpn_packet_t *packet)
        checksum = inet_checksum(ns, sizeof(*ns) + 8, checksum);
 
        if(checksum) {
-               if(debug_lvl >= DEBUG_TRAFFIC)
-                       syslog(LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: checksum error for neighbor solicitation request"));
                return;
        }
 
@@ -460,8 +451,7 @@ void route_neighborsol(vpn_packet_t *packet)
        subnet = lookup_subnet_ipv6((ipv6_t *) & ns->nd_ns_target);
 
        if(!subnet) {
-               if(debug_lvl >= DEBUG_TRAFFIC) {
-                       syslog(LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: neighbor solicitation request for unknown address %hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx"),
                                   ntohs(((uint16_t *) & ns->nd_ns_target)[0]),
                                   ntohs(((uint16_t *) & ns->nd_ns_target)[1]),
                                   ntohs(((uint16_t *) & ns->nd_ns_target)[2]),
@@ -470,7 +460,6 @@ void route_neighborsol(vpn_packet_t *packet)
                                   ntohs(((uint16_t *) & ns->nd_ns_target)[5]),
                                   ntohs(((uint16_t *) & ns->nd_ns_target)[6]),
                                   ntohs(((uint16_t *) & ns->nd_ns_target)[7]));
-               }
 
                return;
        }
@@ -543,9 +532,7 @@ void route_arp(vpn_packet_t *packet)
 
        if(ntohs(arp->arp_hrd) != ARPHRD_ETHER || ntohs(arp->arp_pro) != ETHERTYPE_IP ||
           arp->arp_hln != ETHER_ADDR_LEN || arp->arp_pln != 4 || ntohs(arp->arp_op) != ARPOP_REQUEST) {
-               if(debug_lvl > DEBUG_TRAFFIC) {
-                       syslog(LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
-               }
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: received unknown type ARP request"));
                return;
        }
 
@@ -554,12 +541,9 @@ void route_arp(vpn_packet_t *packet)
        subnet = lookup_subnet_ipv4((ipv4_t *) arp->arp_tpa);
 
        if(!subnet) {
-               if(debug_lvl >= DEBUG_TRAFFIC) {
-                       syslog(LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
+               logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: ARP request for unknown address %d.%d.%d.%d"),
                                   arp->arp_tpa[0], arp->arp_tpa[1], arp->arp_tpa[2],
                                   arp->arp_tpa[3]);
-               }
-
                return;
        }
 
@@ -614,8 +598,7 @@ void route_outgoing(vpn_packet_t *packet)
                                        return;
 
                                default:
-                                       if(debug_lvl >= DEBUG_TRAFFIC)
-                                               syslog(LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
+                                       logger(DEBUG_TRAFFIC, LOG_WARNING, _("Cannot route packet: unknown type %hx"), type);
                                        return;
                        }
                        if(n)