]> arthur.barton.de Git - netatalk.git/blobdiff - etc/atalkd/rtmp.c
Big configure.in cleanup
[netatalk.git] / etc / atalkd / rtmp.c
index dc61575485d7eca1d4990a2c0bc5c95c10fe3f06..727562b0bd31b5dcfcbd7131c8283c3c48d93b6f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rtmp.c,v 1.15 2009-10-13 22:55:37 didg Exp $
+ * $Id: rtmp.c,v 1.17 2009-12-08 03:21:16 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved. See COPYRIGHT.
@@ -400,6 +400,7 @@ int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len
     struct rtmp_tuple  rt, xrt;
     struct gate                *gate;
     struct interface   *iface;
+    struct interface   *iface2;
     struct rtmptab     *rtmp;
     char               *end, packet[ ATP_BUFSIZ ];
     int                 cc;
@@ -413,6 +414,21 @@ int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len
 
     iface = ap->ap_iface;
 
+    /* linux 2.6 sends broadcast queries to the first available socket 
+       (in our case the last configured) 
+       try to find the right one.
+       Note: now a misconfigured or plugged router can broadcast
+       a wrong route
+    */
+    for ( iface2 = interfaces; iface2; iface2 = iface2->i_next ) {
+        if ( iface2->i_rt && from->sat_addr.s_net >= iface2->i_rt->rt_firstnet && 
+                from->sat_addr.s_net <= iface2->i_rt->rt_lastnet) 
+        {
+              iface = iface2;
+        }
+    }
+    /* end of linux 2.6 workaround */
+    
     /* ignore our own packets */
     if ( from->sat_addr.s_net == iface->i_addr.sat_addr.s_net &&
            from->sat_addr.s_node == iface->i_addr.sat_addr.s_node  ) {
@@ -551,13 +567,13 @@ int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len
            }
        }
        if ( !gate ) {  /* new gateway */
-           if (( gate = (struct gate *)malloc( sizeof( struct gate ))) == 0 ) {
+           if (( gate = (struct gate *)malloc( sizeof( struct gate ))) == NULL ) {
                LOG(log_error, logtype_atalkd, "rtmp_packet: malloc: %s", strerror(errno) );
                return -1;
            }
            gate->g_next = iface->i_gate;
-           gate->g_prev = 0;
-           gate->g_rt = 0;
+           gate->g_prev = NULL;
+           gate->g_rt = NULL;
            gate->g_iface = iface;      /* need this? */
            gate->g_sat = *from;
            if ( iface->i_gate ) {
@@ -680,10 +696,10 @@ int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len
                 * we're not likely to be asked for the same tuple twice
                 * in a row.
                 */
-               if ( rtmp->rt_next != 0 ) {
+               if ( rtmp->rt_next != NULL ) {
                    gate->g_rt->rt_prev->rt_next = gate->g_rt;
                    gate->g_rt = rtmp->rt_next;
-                   rtmp->rt_next = 0;
+                   rtmp->rt_next = NULL;
                }
            } else if (( rt.rt_dist & 0x7f ) + 1 > RTMPHOPS_MAX ) {
                LOG(log_info, logtype_atalkd, "rtmp_packet bad hop count from %u.%u for %u",
@@ -708,7 +724,7 @@ int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len
                /*
                 * Add rtmptab entry to end of list (leave head alone).
                 */
-               if ( gate->g_rt == 0 ) {
+               if ( gate->g_rt == NULL ) {
                    rtmp->rt_prev = rtmp;
                    gate->g_rt = rtmp;
                } else {
@@ -751,7 +767,7 @@ int rtmp_packet(struct atport *ap, struct sockaddr_at *from, char *data, int len
         * Request and RDR.
         */
         if (((iface->i_flags & IFACE_ISROUTER) == 0) ||
-           iface->i_rt->rt_zt == 0 ||
+           iface->i_rt->rt_zt == NULL ||
            ( iface->i_flags & IFACE_CONFIG ) == 0 ) {
            return 0;
        }
@@ -814,7 +830,7 @@ int rtmp_request( struct interface *iface)
            break;
        }
     }
-    if ( ap == 0 ) {
+    if ( ap == NULL ) {
        LOG(log_error, logtype_atalkd, "rtmp_request can't find rtmp socket!" );
        return -1;
     }
@@ -972,8 +988,8 @@ newrt(const struct interface *iface)
 {
     struct rtmptab     *rtmp;
 
-    if (( rtmp = (struct rtmptab *)calloc(1, sizeof(struct rtmptab))) == 0 ) {
-       return( 0 );
+    if (( rtmp = (struct rtmptab *)calloc(1, sizeof(struct rtmptab))) == NULL ) {
+       return( NULL );
     }
 
     rtmp->rt_iface = iface;