]> arthur.barton.de Git - netatalk.git/blobdiff - etc/atalkd/main.c
atalkd don't spam syslog if an interface is down, XXX atalkd still advertise routes...
[netatalk.git] / etc / atalkd / main.c
index 7ffab873d6f3dfe4db1ede545ad8ec90198d6b62..469678d3db9ec13273511e7a2157a426e7624a25 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.13 2002-02-13 16:56:20 srittau Exp $
+ * $Id: main.c,v 1.25 2009-12-13 02:21:47 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved. See COPYRIGHT.
 
 #include <sys/param.h>
 #include <sys/socket.h>
-#if defined( sun ) && defined( __svr4__ )
-#include </usr/ucbinclude/sys/file.h>
-#else /* sun __svr4__ */
 #include <sys/file.h>
-#endif /* sun __svr4__ */
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/ioctl.h>
@@ -31,6 +27,9 @@
 #ifndef WIFEXITED
 #define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
 #endif /* ! WIFEXITED */
+#ifndef WIFSTOPPED
+#define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
+#endif
 
 #include <errno.h>
 #ifdef TRU64
@@ -56,6 +55,7 @@
 #include <atalk/compat.h>
 #include <atalk/zip.h>
 #include <atalk/rtmp.h>
+#include <atalk/nbp.h>
 #include <atalk/ddp.h>
 #include <atalk/atp.h>
 #include <atalk/paths.h>
@@ -71,6 +71,7 @@
 #include "list.h"
 #include "rtmp.h"
 #include "zip.h"
+#include "nbp.h"
 #include "atserv.h"
 #include "main.h"
 
@@ -98,34 +99,33 @@ int ifconfig(const char *iname, unsigned long cmd, struct sockaddr_at *sa);
 
 #define PKTSZ  1024
 
-extern int     rtmp_packet();
-extern int     nbp_packet();
-extern int     aep_packet();
-extern int     zip_packet();
+extern int aep_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len);
 
 int            rtfd;
+int            transition = 0;
+int            stabletimer, newrtmpdata = 0;
 
-struct atserv  atserv[] = {
+static struct atserv   atserv[] = {
     { "rtmp",          1,      rtmp_packet },          /* 0 */
     { "nbp",           2,      nbp_packet },           /* 1 */
     { "echo",          4,      aep_packet },           /* 2 */
     { "zip",           6,      zip_packet },           /* 3 */
 };
-int            atservNATSERV = elements( atserv );
+static int             atservNATSERV = elements( atserv );
 
 struct interface       *interfaces = NULL, *ciface = NULL;
 
-int            debug = 0, quiet = 0, chatty = 0;
-char           *configfile = NULL;
-int            ziptimeout = 0, transition = 0;
-int            stabletimer, stable = 0, newrtmpdata = 0, noparent = 0;
-static int     ninterfaces;
-int            defphase = IFACE_PHASE2;
-int            nfds = 0;
-fd_set         fds;
-char           Packet[ PKTSZ ];
-char           *version = VERSION;
-static char     *pidfile = _PATH_ATALKDLOCK;
+static int             debug = 0, quiet = 0, chatty = 0;
+static char            *configfile = NULL;
+static int             ziptimeout = 0;
+static int             stable = 0, noparent = 0;
+static int             ninterfaces;
+static int             defphase = IFACE_PHASE2;
+static int             nfds = 0;
+static fd_set          fds;
+static char            Packet[ PKTSZ ];
+static char            *version = VERSION;
+static char            *pidfile = _PATH_ATALKDLOCK;
 
 
 /* from config.c */
@@ -149,10 +149,14 @@ static void atalkd_exit(const int i)
        continue;
 #endif /* SIOCDIFADDR != SIOCATALKDIFADDR */
 #endif /* SIOCATALKIFADDR */
-      LOG(log_error, logtype_default, "difaddr(%u.%u): %s", 
+      LOG(log_error, logtype_atalkd, "difaddr(%u.%u): %s", 
              ntohs(iface->i_addr.sat_addr.s_net), 
              iface->i_addr.sat_addr.s_node, strerror(errno));
     }
+#ifdef linux
+    if (!(iface->i_flags & IFACE_WASALLMULTI) && (iface->i_flags & IFACE_ALLMULTI))
+        ifsetallmulti(iface->i_name, 0);
+#endif /* linux */
   }
 #endif /* SOPCDOFADDR */
 
@@ -160,8 +164,32 @@ static void atalkd_exit(const int i)
   exit(i);
 }
 
+/* XXX need better error handling for gone interfaces, delete routes and so on 
+ * moreover there's no way to put an interface back short of restarting atalkd
+ * thus after the first time, silently fail
+*/
+static ssize_t sendto_iface(struct interface *iface, int sockfd, const void *buf, size_t len, 
+                       const struct sockaddr_at         *dest_addr)
+{
+    ssize_t ret = sendto( sockfd, buf, len, 0, (struct sockaddr *)dest_addr, sizeof( struct sockaddr_at ));
+
+    if (ret < 0 ) {
+        if (!(iface->i_flags & IFACE_ERROR)) {
+            LOG(log_error, logtype_atalkd, "as_timer sendto %u.%u (%u): %s",
+                                   ntohs( dest_addr->sat_addr.s_net ),
+                                   dest_addr->sat_addr.s_node,
+                                   ntohs( iface->i_rt->rt_firstnet ),
+                                   strerror(errno) );
+        }
+        iface->i_flags |= IFACE_ERROR;
+    }
+    else {
+        iface->i_flags &= ~IFACE_ERROR;
+    }
+    return ret;
+}
 
-void as_timer(void)
+static void as_timer(int sig _U_)
 {
     struct sockaddr_at sat;
     struct ziphdr      zh;
@@ -176,7 +204,10 @@ void as_timer(void)
     int                        sentzipq = 0;
     int                        n, cc;
 
+    ap=zap=rap=NULL;
+
     memset(&sat, 0, sizeof( struct sockaddr_at ));
+
     for ( iface = interfaces; iface; iface = iface->i_next ) {
        if ( iface->i_flags & IFACE_LOOPBACK ) {
            continue;
@@ -190,18 +221,17 @@ void as_timer(void)
            }
        }
 
-       if (( iface->i_flags & ( IFACE_ADDR|IFACE_CONFIG|IFACE_NOROUTER )) ==
-               IFACE_ADDR ) {
+       if (( iface->i_flags & ( IFACE_ADDR|IFACE_CONFIG|IFACE_NOROUTER )) == IFACE_ADDR ) {
            if ( iface->i_time < 3 ) {
                if ( iface->i_flags & IFACE_PHASE1 ) {
                  if (rtmp_request( iface ) < 0) {
-                     LOG(log_error, logtype_default, "rtmp_request: %s", strerror(errno));
+                     LOG(log_error, logtype_atalkd, "rtmp_request: %s", strerror(errno));
                      atalkd_exit(1);
                  }
                    newrtmpdata = 1;
                } else {
                  if (zip_getnetinfo( iface ) < 0) {
-                   LOG(log_error, logtype_default, "zip_getnetinfo: %s", strerror(errno));
+                   LOG(log_error, logtype_atalkd, "zip_getnetinfo: %s", strerror(errno));
                    atalkd_exit(1);
                  }
                  sentzipq = 1;
@@ -215,11 +245,9 @@ void as_timer(void)
                         * No seed info, and we've got multiple interfaces.
                         * Wait forever.
                         */
-                       LOG(log_info, logtype_default,
-                               "as_timer multiple interfaces, no seed" );
-                       LOG(log_info, logtype_default, "as_timer can't configure %s",
-                               iface->i_name );
-                       LOG(log_info, logtype_default, "as_timer waiting for router" );
+                       LOG(log_info, logtype_atalkd, "as_timer multiple interfaces, no seed" );
+                       LOG(log_info, logtype_atalkd, "as_timer can't configure %s", iface->i_name );
+                       LOG(log_info, logtype_atalkd, "as_timer waiting for router" );
                        iface->i_time = 0;
                        continue;
                    } else {
@@ -229,9 +257,8 @@ void as_timer(void)
                         */
                        iface->i_flags |= IFACE_CONFIG;
                        for ( zt = iface->i_czt; zt; zt = zt->zt_next ) {
-                           if (addzone( iface->i_rt, zt->zt_len, 
-                                        zt->zt_name) < 0) {
-                             LOG(log_error, logtype_default, "addzone: %s", strerror(errno));
+                           if (addzone( iface->i_rt, zt->zt_len, zt->zt_name) < 0) {
+                             LOG(log_error, logtype_atalkd, "addzone: %s", strerror(errno));
                              atalkd_exit(1);
                            }
                        }
@@ -240,26 +267,20 @@ void as_timer(void)
                            iface->i_rt->rt_flags |= RTMPTAB_HASZONES;
                        }
                        if ( iface->i_flags & IFACE_PHASE1 ) {
-                           LOG(log_info, logtype_default,
-                                   "as_timer configured %s phase 1 from seed",
-                                   iface->i_name );
+                           LOG(log_info, logtype_atalkd, "as_timer configured %s phase 1 from seed", iface->i_name );
                            setaddr( iface, IFACE_PHASE1,
                                    iface->i_caddr.sat_addr.s_net,
                                    iface->i_addr.sat_addr.s_node,
                                    iface->i_caddr.sat_addr.s_net,
                                    iface->i_caddr.sat_addr.s_net );
                        } else {
-                           LOG(log_info, logtype_default,
-                                   "as_timer configured %s phase 2 from seed",
-                                   iface->i_name );
+                           LOG(log_info, logtype_atalkd, "as_timer configured %s phase 2 from seed", iface->i_name );
                        }
 
                        if ( looproute( iface, RTMP_ADD )) { /* -1 or 1 */
-                           LOG(log_error, logtype_default,
-                                   "as_timer: can't route %u.%u to loop: %s",
-                                   ntohs( iface->i_addr.sat_addr.s_net ),
-                                   iface->i_addr.sat_addr.s_node,
-                                   strerror(errno) );
+                           LOG(log_error, logtype_atalkd, "as_timer: can't route %u.%u to loop: %s", 
+                                   ntohs( iface->i_addr.sat_addr.s_net ),
+                                   iface->i_addr.sat_addr.s_node, strerror(errno) );
                            atalkd_exit( 1 );
                        }
                        if ( iface == ciface ) {
@@ -272,21 +293,17 @@ void as_timer(void)
                     * Configure for no router operation.  Wait for a route
                     * to become available in rtmp_packet().
                     */
-                   LOG(log_info, logtype_default, "config for no router" );
+                   LOG(log_info, logtype_atalkd, "config for no router" );
                      
                    if ( iface->i_flags & IFACE_PHASE2 ) {
-                       iface->i_rt->rt_firstnet = htons(1);
+                       iface->i_rt->rt_firstnet = 0;
                        iface->i_rt->rt_lastnet = htons( STARTUP_LASTNET );
-                       setaddr( iface, IFACE_PHASE2,
-                               iface->i_addr.sat_addr.s_net,
-                               iface->i_addr.sat_addr.s_node,
-                               htons(1), htons( STARTUP_LASTNET ));
+                       setaddr( iface, IFACE_PHASE2, iface->i_addr.sat_addr.s_net, iface->i_addr.sat_addr.s_node,
+                               0, htons( STARTUP_LASTNET ));
                    }
                    if ( looproute( iface, RTMP_ADD ) ) { /* -1 or 1 */
-                       LOG(log_error, logtype_default,
-                               "as_timer: can't route %u.%u to loopback: %s",
-                               ntohs( iface->i_addr.sat_addr.s_net ),
-                               iface->i_addr.sat_addr.s_node,
+                       LOG(log_error, logtype_atalkd, "as_timer: can't route %u.%u to loopback: %s",
+                               ntohs( iface->i_addr.sat_addr.s_net ), iface->i_addr.sat_addr.s_node,
                                strerror(errno) );
                        atalkd_exit( 1 );
                    }
@@ -318,19 +335,17 @@ void as_timer(void)
             * our zone has gone away.
             */
            if ( ++gate->g_state >= RTMPTAB_BAD ) {
-               LOG(log_info, logtype_default, "as_timer gateway %u.%u down",
-                       ntohs( gate->g_sat.sat_addr.s_net ),
+               LOG(log_info, logtype_atalkd, "as_timer gateway %u.%u down", ntohs( gate->g_sat.sat_addr.s_net ),
                        gate->g_sat.sat_addr.s_node );
                rtmp = gate->g_rt;
                while ( rtmp ) {
                    frtmp = rtmp->rt_next;
-                   if ( rtmp->rt_hops == RTMPHOPS_POISON ||
-                           rtmp->rt_iprev == 0 ) {
+                   if ( rtmp->rt_hops == RTMPHOPS_POISON || rtmp->rt_iprev == NULL ) {
                        rtmp_free( rtmp );
                    } else {
                        rtmp->rt_hops = RTMPHOPS_POISON;
                        if ((cc = rtmp_replace( rtmp )) < 0) {
-                         LOG(log_error, logtype_default, "rtmp_replace: %s", strerror(errno));
+                         LOG(log_error, logtype_atalkd, "rtmp_replace: %s", strerror(errno));
                          atalkd_exit(1);
                        }
                        if (cc) {
@@ -339,13 +354,13 @@ void as_timer(void)
                    }
                    rtmp = frtmp;
                }
-               if ( gate->g_rt == 0 ) {
-                   if ( gate->g_prev == 0 ) {
+               if ( gate->g_rt == NULL ) {
+                   if ( gate->g_prev == NULL ) {
                        gate->g_iface->i_gate = gate->g_next;
                    } else {
                        gate->g_prev->g_next = gate->g_next;
                    }
-                   if ( gate->g_next != 0 ) {
+                   if ( gate->g_next != NULL ) {
                        gate->g_next->g_prev = gate->g_prev;
                    }
                    fgate = gate;       /* can't free here, just mark it */
@@ -360,8 +375,7 @@ void as_timer(void)
                 * if we're not a seed router.
                 */
 
-               if ( gate->g_iface->i_gate == 0 && 
-                    ((iface->i_flags & IFACE_SEED) == 0)) {
+               if ( gate->g_iface->i_gate == NULL && ((iface->i_flags & IFACE_SEED) == 0)) {
                    gate->g_iface->i_flags |= IFACE_NOROUTER;
                    gate->g_iface->i_flags &= ~IFACE_CONFIG;
 
@@ -371,7 +385,7 @@ void as_timer(void)
                      gate->g_iface->i_rt->rt_flags &= ~RTMPTAB_HASZONES;
                    }
 
-                   LOG(log_info, logtype_default, "as_timer last gateway down" );
+                   LOG(log_info, logtype_atalkd, "as_timer last gateway down" );
 
                    /* Set netrange to 0-fffe.  */
                    if ( gate->g_iface->i_flags & IFACE_PHASE2 ) {
@@ -418,7 +432,7 @@ void as_timer(void)
                 */
                if ( rtmp->rt_state >= RTMPTAB_BAD ) {
                    frtmp = rtmp->rt_next;
-                   if ( rtmp->rt_iprev == 0 ) {        /* not in use */
+                   if ( rtmp->rt_iprev == NULL ) {     /* not in use */
                        rtmp_free( rtmp );
                    } else {                            /* in use */
                        if ( rtmp->rt_hops == RTMPHOPS_POISON ) {
@@ -426,7 +440,7 @@ void as_timer(void)
                        } else {
                            rtmp->rt_hops = RTMPHOPS_POISON;
                            if ((cc = rtmp_replace( rtmp )) < 0) {
-                               LOG(log_error, logtype_default, "rtmp_replace: %s", strerror(errno));
+                               LOG(log_error, logtype_atalkd, "rtmp_replace: %s", strerror(errno));
                                atalkd_exit(1);
                            }
                            if (cc)
@@ -440,8 +454,7 @@ void as_timer(void)
                /*
                 * Do ZIP lookups.
                 */
-               if ( rtmp->rt_iprev &&
-                       ( rtmp->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
+               if ( rtmp->rt_iprev && ( rtmp->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
                    if ( data + sizeof( u_short ) > end || n == 255 ) {
                        /* send what we've got */
                        zh.zh_op = ZIPOP_QUERY;
@@ -451,11 +464,7 @@ void as_timer(void)
                        *data++ = DDPTYPE_ZIP;
                        memcpy( data, &zh, sizeof( struct ziphdr ));
 
-                       if ( sendto( zap->ap_fd, packet, cc, 0,
-                               (struct sockaddr *)&sat,
-                               sizeof( struct sockaddr_at )) < 0 ) {
-                           LOG(log_error, logtype_default, "as_timer sendto: %s", strerror(errno) );
-                       }
+                       sendto_iface(iface,  zap->ap_fd, packet, cc, &sat);
                        sentzipq = 1;
 
                        n = 0;
@@ -473,8 +482,7 @@ void as_timer(void)
                     * ask about, and warn that we can't get it's zone.
                     */
                    if ( rtmp->rt_nzq++ == 3 ) {
-                       LOG(log_info, logtype_default, "as_timer can't get zone for %u",
-                               ntohs( rtmp->rt_firstnet ));
+                       LOG(log_info, logtype_atalkd, "as_timer can't get zone for %u", ntohs( rtmp->rt_firstnet ));
                    }
                    if ( rtmp->rt_nzq > 3 ) {
                        if ( ziptimeout ) {
@@ -501,10 +509,7 @@ void as_timer(void)
                *data++ = DDPTYPE_ZIP;
                memcpy( data, &zh, sizeof( struct ziphdr ));
 
-               if ( sendto( zap->ap_fd, packet, cc, 0, (struct sockaddr *)&sat,
-                       sizeof( struct sockaddr_at )) < 0 ) {
-                   LOG(log_error, logtype_default, "as_timer sendto: %s", strerror(errno) );
-               }
+               sendto_iface( iface, zap->ap_fd, packet, cc, &sat);
            }
        }
        if ( fgate ) {
@@ -570,31 +575,27 @@ void as_timer(void)
                 */
                for ( rtmp = iface2->i_rt; rtmp; rtmp = rtmp->rt_inext ) {
                    /* don't broadcast routes we have no zone for */
-                   if ( rtmp->rt_zt == 0 ||
+                   if ( rtmp->rt_zt == NULL ||
                            ( rtmp->rt_flags & RTMPTAB_ZIPQUERY ) ||
                            ( rtmp->rt_flags & RTMPTAB_HASZONES ) == 0 ) {
                        continue;
                    }
 
+                   /* split horizon */
+                   if (rtmp->rt_iface == iface) {
+                       continue;
+                   }
+
                    if ((( rtmp->rt_flags & RTMPTAB_EXTENDED ) &&
                            data + 2 * SZ_RTMPTUPLE > end ) ||
                            data + SZ_RTMPTUPLE > end ) {
-                       if ( sendto( rap->ap_fd, packet, data - packet, 0,
-                               (struct sockaddr *)&sat,
-                               sizeof( struct sockaddr_at )) < 0 ) {
-                           LOG(log_error, logtype_default, "as_timer sendto %u.%u (%u): %s",
-                                   ntohs( sat.sat_addr.s_net ),
-                                   sat.sat_addr.s_node,
-                                   ntohs( iface->i_rt->rt_firstnet ),
-                                   strerror(errno) );
-                       }
+
+                       sendto_iface(iface,rap->ap_fd, packet, data - packet, &sat);
 
                        if ( iface->i_flags & IFACE_PHASE2 ) {
-                           data = packet + 1 + sizeof( struct rtmp_head ) +
-                                   2 * SZ_RTMPTUPLE;
+                           data = packet + 1 + sizeof( struct rtmp_head ) + 2 * SZ_RTMPTUPLE;
                        } else {
-                           data = packet + 1 + sizeof( struct rtmp_head ) +
-                                   SZ_RTMPTUPLE;
+                           data = packet + 1 + sizeof( struct rtmp_head ) + SZ_RTMPTUPLE;
                        }
                        n = 0;
                    }
@@ -619,15 +620,7 @@ void as_timer(void)
 
            /* send rest */
            if ( n ) {
-               if ( sendto( rap->ap_fd, packet, data - packet, 0,
-                       (struct sockaddr *)&sat,
-                       sizeof( struct sockaddr_at )) < 0 ) {
-                   LOG(log_error, logtype_default, "as_timer sendto %u.%u (%u): %s",
-                           ntohs( sat.sat_addr.s_net ),
-                           sat.sat_addr.s_node,
-                           ntohs( iface->i_rt->rt_firstnet ),
-                           strerror(errno) );
-               }
+               sendto_iface(iface, rap->ap_fd, packet, data - packet, &sat);
            }
        }
     }
@@ -653,14 +646,14 @@ void as_timer(void)
 
        if ( stable && !noparent ) {
            noparent = 1;
-           LOG(log_info, logtype_default, "ready %d/%d/%d", stabletimer, newrtmpdata,
+           LOG(log_info, logtype_atalkd, "ready %d/%d/%d", stabletimer, newrtmpdata,
                    sentzipq );
            if ( !debug ) {
                /*
                 * Seems like we could get here more than once...
                 */
                if ( kill( getpid(), SIGSTOP ) < 0 ) {
-                   LOG(log_error, logtype_default, "as_timer: kill-self failed!" );
+                   LOG(log_error, logtype_atalkd, "as_timer: kill-self failed!" );
                    atalkd_exit( 1 );
                }
            }
@@ -686,7 +679,7 @@ consistency()
        for ( lr = zt->zt_rt; lr; lr = lr->l_next ) {
            rtmp = (struct rtmptab *)lr->l_data;
            if ( rtmp->rt_iprev == 0 && rtmp->rt_gate != 0 ) {
-               LOG(log_error, logtype_default, "%.*s has %u-%u (unused)\n",
+               LOG(log_error, logtype_atalkd, "%.*s has %u-%u (unused)",
                        zt->zt_len, zt->zt_name, ntohs( rtmp->rt_firstnet ),
                        ntohs( rtmp->rt_lastnet ));
                atalkd_exit(1);
@@ -697,7 +690,7 @@ consistency()
                }
            }
            if ( lz == 0 ) {
-               LOG(log_error, logtype_default, "no map from %u-%u to %.*s\n", 
+               LOG(log_error, logtype_atalkd, "no map from %u-%u to %.*s", 
                        ntohs( rtmp->rt_firstnet ),
                        ntohs( rtmp->rt_lastnet ),
                        zt->zt_len, zt->zt_name );
@@ -708,10 +701,8 @@ consistency()
 }
 #endif /* DEBUG */
 
-#if !defined( ibm032 ) && !defined( _IBMR2 )
-    void
-#endif /* ! ibm032 && ! _IBMR2 */
-as_debug()
+static void
+as_debug(int sig _U_)
 {
     struct interface   *iface;
     struct list                *l;
@@ -721,7 +712,7 @@ as_debug()
     FILE               *rtmpdebug;
 
     if (( rtmpdebug = fopen( _PATH_ATALKDEBUG, "w" )) == NULL ) {
-       LOG(log_error, logtype_default, "rtmp: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "rtmp: %s", strerror(errno) );
     }
 
     for ( iface = interfaces; iface; iface = iface->i_next ) {
@@ -812,10 +803,8 @@ as_debug()
 /*
  * Called when SIGTERM is recieved.  Remove all routes and then exit.
  */
-#if !defined( ibm032 ) && !defined( _IBMR2 )
-    void
-#endif /* ! ibm032 && ! _IBMR2 */
-as_down()
+static void
+as_down(int sig _U_)
 {
     struct interface   *iface;
     struct gate                *gate;
@@ -826,7 +815,7 @@ as_down()
            for ( rt = gate->g_rt; rt; rt = rt->rt_next ) {
                if ( rt->rt_iprev ) {
                    if ( gateroute( RTMP_DEL, rt ) < 0 ) {
-                       LOG(log_error, logtype_default, "as_down remove %u-%u failed: %s",
+                       LOG(log_error, logtype_atalkd, "as_down remove %u-%u failed: %s",
                                ntohs( rt->rt_firstnet ),
                                ntohs( rt->rt_lastnet ),
                                strerror(errno) );
@@ -836,7 +825,7 @@ as_down()
        }
        if ( iface->i_flags & IFACE_LOOP ) {
          if (looproute( iface, RTMP_DEL )) {
-           LOG(log_error, logtype_default, "as_down remove %s %u.%u failed: %s",
+           LOG(log_error, logtype_atalkd, "as_down remove %s %u.%u failed: %s",
                    iface->i_name, ntohs( iface->i_addr.sat_addr.s_net ),
                    iface->i_addr.sat_addr.s_node,
                    strerror(errno) );
@@ -844,13 +833,11 @@ as_down()
        }
     }
 
-    LOG(log_info, logtype_default, "done" );
+    LOG(log_info, logtype_atalkd, "done" );
     atalkd_exit( 0 );
 }
 
-int main( ac, av )
-    int                ac;
-    char       **av;
+int main( int ac, char **av)
 {
     extern char         *optarg;
     extern int          optind;
@@ -858,14 +845,15 @@ int main( ac, av )
     struct sockaddr_at sat;
     struct sigaction   sv;
     struct itimerval   it;
+    sigset_t            signal_set, old_set;
+    
     struct interface   *iface;
     int                        status;
     struct atport      *ap;
     fd_set             readfds;
-    int                        i, mask, c;
+    int                        i, c;
     SOCKLEN_T          fromlen;
     char               *prog;
-;
 
     while (( c = getopt( ac, av, "12qsdtf:P:v" )) != EOF ) {
        switch ( c ) {
@@ -1020,6 +1008,12 @@ int main( ac, av )
        exit( 1 );
     }
 
+    /*
+     * Set process name for logging
+     */
+
+    set_processname("atalkd");
+
     /* do this here so that we can use ifconfig */
 #ifdef __svr4__
     if ( plumb() < 0 ) {
@@ -1084,7 +1078,7 @@ int main( ac, av )
     syslog_setup(log_debug, logtype_default, logoption_pid, logfacility_daemon );
 #endif /* ultrix */
 
-    LOG(log_info, logtype_default, "restart (%s)", version );
+    LOG(log_info, logtype_atalkd, "restart (%s)", version );
 
     /*
      * Socket for use in routing ioctl()s. Can't add routes to our
@@ -1092,20 +1086,23 @@ int main( ac, av )
      */
 #ifdef BSD4_4
     if (( rtfd = socket( PF_ROUTE, SOCK_RAW, AF_APPLETALK )) < 0 ) {
-       LOG(log_error, logtype_default, "route socket: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "route socket: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
     if ( shutdown( rtfd, 0 ) < 0 ) {
-       LOG(log_error, logtype_default, "route shutdown: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "route shutdown: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
 #else /* BSD4_4 */
     if (( rtfd = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-       LOG(log_error, logtype_default, "route socket: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "route socket: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
 #endif /* BSD4_4 */
 
+    ciface = interfaces;
+    bootaddr( ciface );
+
     memset(&sv, 0, sizeof(sv));
     sv.sa_handler = as_down;
     sigemptyset( &sv.sa_mask );
@@ -1114,7 +1111,7 @@ int main( ac, av )
     sigaddset( &sv.sa_mask, SIGTERM );
     sv.sa_flags = SA_RESTART;
     if ( sigaction( SIGTERM, &sv, NULL) < 0 ) {
-       LOG(log_error, logtype_default, "sigterm: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "sigterm: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
 
@@ -1125,7 +1122,7 @@ int main( ac, av )
     sigaddset( &sv.sa_mask, SIGTERM );
     sv.sa_flags = SA_RESTART;
     if ( sigaction( SIGUSR1, &sv, NULL) < 0 ) {
-       LOG(log_error, logtype_default, "sigusr1: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "sigusr1: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
 
@@ -1136,7 +1133,7 @@ int main( ac, av )
     sigaddset( &sv.sa_mask, SIGTERM );
     sv.sa_flags = SA_RESTART;
     if ( sigaction( SIGALRM, &sv, NULL) < 0 ) {
-       LOG(log_error, logtype_default, "sigalrm: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "sigalrm: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
 
@@ -1145,12 +1142,18 @@ int main( ac, av )
     it.it_value.tv_sec = 10L;
     it.it_value.tv_usec = 0L;
     if ( setitimer( ITIMER_REAL, &it, NULL) < 0 ) {
-       LOG(log_error, logtype_default, "setitimer: %s", strerror(errno) );
+       LOG(log_error, logtype_atalkd, "setitimer: %s", strerror(errno) );
        atalkd_exit( 1 );
     }
 
-    ciface = interfaces;
-    bootaddr( ciface );
+    sigemptyset( &signal_set );
+    sigaddset(&signal_set, SIGALRM);
+#if 0
+    /* don't block SIGTERM */
+    sigaddset(&signal_set, SIGTERM);
+#endif
+    sigaddset(&signal_set, SIGUSR1);
+
     for (;;) {
        readfds = fds;
        if ( select( nfds, &readfds, NULL, NULL, NULL) < 0 ) {
@@ -1158,7 +1161,7 @@ int main( ac, av )
                errno = 0;
                continue;
            } else {
-               LOG(log_error, logtype_default, "select: %s", strerror(errno) );
+               LOG(log_error, logtype_atalkd, "select: %s", strerror(errno) );
                atalkd_exit( 1 );
            }
        }
@@ -1170,10 +1173,10 @@ int main( ac, av )
                        fromlen = sizeof( struct sockaddr_at );
                        if (( c = recvfrom( ap->ap_fd, Packet, sizeof( Packet ),
                                0, (struct sockaddr *)&sat, &fromlen )) < 0 ) {
-                           LOG(log_error, logtype_default, "recvfrom: %s", strerror(errno) );
+                           LOG(log_error, logtype_atalkd, "recvfrom: %s", strerror(errno) );
                            continue;
                        }
-#ifdef DEBUG
+#ifdef DEBUG1
                        if ( debug ) {
                            printf( "packet from %u.%u on %s (%x) %d (%d)\n",
                                    ntohs( sat.sat_addr.s_net ),
@@ -1181,32 +1184,25 @@ int main( ac, av )
                                    iface->i_flags, ap->ap_port, ap->ap_fd );
                            bprint( Packet, c );
                        }
-#endif /* DEBUG */
-#ifdef __svr4__
-                       if ( sighold( SIGALRM ) || sighold( SIGUSR1 )) {
-                           LOG(log_error, logtype_default, "sighold: %s", strerror(errno) );
+#endif 
+                       if (sigprocmask(SIG_BLOCK, &signal_set, &old_set) < 0) {
+                           LOG(log_error, logtype_atalkd, "sigprocmask: %s", strerror(errno) );
                            atalkd_exit( 1 );
                        }
-#else /* __svr4__ */
-                       mask = sigsetmask( sigmask( SIGALRM ) |
-                               sigmask( SIGUSR1 ));
-#endif /* __svr4__ */
+
                        if (( *ap->ap_packet )( ap, &sat, Packet, c ) < 0) {
-                         LOG(log_error, logtype_default, "ap->ap_packet: %s", strerror(errno));
+                         LOG(log_error, logtype_atalkd, "ap->ap_packet: %s", strerror(errno));
                          atalkd_exit(1);
                        }
 
 #ifdef DEBUG
                        consistency();
-#endif /* DEBUG */
-#ifdef __svr4__
-                       if ( sigrelse( SIGUSR1 ) || sigrelse( SIGALRM )) {
-                           LOG(log_error, logtype_default, "sigrelse: %s", strerror(errno) );
+#endif 
+                       if (sigprocmask(SIG_SETMASK, &old_set, NULL) < 0) {
+                           LOG(log_error, logtype_atalkd, "sigprocmask old set: %s", strerror(errno) );
                            atalkd_exit( 1 );
                        }
-#else /* __svr4__ */
-                       sigsetmask( mask );
-#endif /* __svr4__ */
+
                    }
                }
            }
@@ -1219,16 +1215,15 @@ int main( ac, av )
  * and rtmp_packet()) to set the initial "bootstrapping" address
  * on an interface.
  */
-void bootaddr( iface )
-    struct interface   *iface;
+void bootaddr(struct interface *iface)
 {
-    if ( iface == 0 ) {
+    if ( iface == NULL ) {
        return;
     }
 
     /* consistency */
     if ( iface->i_flags & IFACE_ADDR ) {
-       LOG(log_error, logtype_default, "bootaddr OOPS!" );
+       LOG(log_error, logtype_atalkd, "bootaddr OOPS!" );
        atalkd_exit(1);
     }
 
@@ -1244,7 +1239,7 @@ void bootaddr( iface )
            }
 
        } else if (rtmp_request( iface ) < 0) {
-         LOG(log_error, logtype_default, "bootaddr (rtmp_request): %s", strerror(errno));
+         LOG(log_error, logtype_atalkd, "bootaddr (rtmp_request): %s", strerror(errno));
          atalkd_exit(1);
        }
 
@@ -1261,7 +1256,7 @@ void bootaddr( iface )
            }
            
        } else if (zip_getnetinfo( iface ) < 0) {
-         LOG(log_error, logtype_default, "bootaddr (zip_getnetinfo): %s", strerror(errno));
+         LOG(log_error, logtype_atalkd, "bootaddr (zip_getnetinfo): %s", strerror(errno));
          atalkd_exit(1);
        }
     }
@@ -1289,13 +1284,13 @@ void setaddr(struct interface *iface,
     if ( iface->i_ports == NULL ) {    /* allocate port structures */
        for ( i = 0, as = atserv; i < atservNATSERV; i++, as++ ) {
            if (( se = getservbyname( as->as_name, "ddp" )) == NULL ) {
-               LOG(log_info, logtype_default, "%s: service unknown", as->as_name );
+               LOG(log_info, logtype_atalkd, "%s: service unknown", as->as_name );
            } else {
                as->as_port = ntohs( se->s_port );
            }
            if (( ap = (struct atport *)malloc( sizeof( struct atport ))) ==
                    NULL ) {
-               LOG(log_error, logtype_default, "malloc: %s", strerror(errno) );
+               LOG(log_error, logtype_atalkd, "malloc: %s", strerror(errno) );
                atalkd_exit( 1 );
            }
            ap->ap_fd = 0;
@@ -1325,23 +1320,24 @@ void setaddr(struct interface *iface,
     memcpy( iface->i_addr.sat_zero, &nr, sizeof( struct netrange ));
 
     if ( ifconfig( iface->i_name, SIOCSIFADDR, &iface->i_addr )) {
-      LOG(log_error, logtype_default, "setifaddr: %s (%u-%u): %s. try specifying a \
+      LOG(log_error, logtype_atalkd, "setifaddr: %s (%u-%u): %s. try specifying a \
 smaller net range.", iface->i_name, ntohs(first), ntohs(last), strerror(errno));
        atalkd_exit( 1 );
     }
     if ( ifconfig( iface->i_name, SIOCGIFADDR, &iface->i_addr )) {
-       LOG(log_error, logtype_default, "getifaddr: %s: %s", iface->i_name, strerror(errno) );
+       LOG(log_error, logtype_atalkd, "getifaddr: %s: %s", iface->i_name, strerror(errno) );
        atalkd_exit( 1 );
     }
 
     /* open ports */
     i = 1; /* enable broadcasts */
-#ifdef __svr4__ 
-    LOG(log_info, logtype_default, "setsockopt incompatible w/ Solaris STREAMS module.");
+#if 0
+    /* useless message, no? */
+    LOG(log_info, logtype_atalkd, "setsockopt incompatible w/ Solaris STREAMS module.");
 #endif /* __svr4__ */
     for ( ap = iface->i_ports; ap; ap = ap->ap_next ) {
        if (( ap->ap_fd = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
-           LOG(log_error, logtype_default, "socket: %s", strerror(errno) );
+           LOG(log_error, logtype_atalkd, "socket: %s", strerror(errno) );
            atalkd_exit( 1 );
        }
 #ifndef __svr4__
@@ -1359,7 +1355,7 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last), strerror(errno));
 
        if ( bind( ap->ap_fd, (struct sockaddr *)&sat,
                sizeof( struct sockaddr_at )) < 0 ) {
-           LOG(log_error, logtype_default, "bind %u.%u:%u: %s",
+           LOG(log_error, logtype_atalkd, "bind %u.%u:%u: %s",
                    ntohs( sat.sat_addr.s_net ),
                    sat.sat_addr.s_node, sat.sat_port, strerror(errno) );
 #ifdef SIOCDIFADDR
@@ -1391,10 +1387,42 @@ smaller net range.", iface->i_name, ntohs(first), ntohs(last), strerror(errno));
     nfds++;
 }
 
-int ifconfig( iname, cmd, sa )
-    const char         *iname;
-    unsigned long      cmd;
-    struct sockaddr_at *sa;
+int ifsetallmulti (const char *iname, int set)
+{
+    int sock;
+    struct ifreq ifr;
+
+    memset(&ifr, 0, sizeof(ifr));
+
+    if (( sock = socket( AF_APPLETALK, SOCK_DGRAM, 0 )) < 0 ) {
+        return( -1 );
+    }
+
+    /* get interface config */
+    strlcpy(ifr.ifr_name, iname, sizeof(ifr.ifr_name));
+    if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0) {
+        close(sock);
+        return (-1);
+    }
+
+    /* should we set or unset IFF_ALLMULTI */
+    if (set)
+           ifr.ifr_flags |= IFF_ALLMULTI;
+    else
+           ifr.ifr_flags &= ~IFF_ALLMULTI;
+
+    /* set interface config */
+    strlcpy(ifr.ifr_name, iname, sizeof(ifr.ifr_name));
+    if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0) {
+        close(sock);   
+        return -1;
+    }
+
+    close(sock);
+    return (0);
+}
+
+int ifconfig( const char *iname, unsigned long cmd, struct sockaddr_at *sa)
 {
     struct ifreq       ifr;
     int                        s;
@@ -1417,8 +1445,7 @@ int ifconfig( iname, cmd, sa )
     return( 0 );
 }
 
-void dumpconfig( iface )
-    struct interface   *iface;
+void dumpconfig( struct interface *iface)
 {
     struct list                *l;
 
@@ -1454,7 +1481,7 @@ void dumpconfig( iface )
 }
 
 #ifdef DEBUG
-void dumproutes()
+void dumproutes(void)
 {
     struct interface   *iface;
     struct rtmptab     *rtmp;
@@ -1502,7 +1529,7 @@ void dumproutes()
     fflush( stdout );
 }
 
-void dumpzones()
+void dumpzones(void)
 {
     struct interface   *iface;
     struct rtmptab     *rtmp;