Hi,

Yesterday I proposed a patch on to limit avahi to a specific interface based on the source address when opening each socket. As a real Michael Niedermayer, Sjoerd shot the patch on sight and suggested an interface based approach.

This patch tries to accomplish to limit the used interfaces based on a user defined list in the daemon configuration file. The idea would be if the list is not defined, it will just process every found interface, if the list is present, it will iterate over the list for every found interface. A todo is clean the list from duplicates.

The patch compiles on svn, but I have not yet tested it. Open for more feedback!


Signed-off-by: Stefan de Konink <[EMAIL PROTECTED]>


Yours Sincerely,

Stefan de Konink
Index: avahi-daemon/main.c
===================================================================
--- avahi-daemon/main.c (revision 1781)
+++ avahi-daemon/main.c (working copy)
@@ -601,6 +601,19 @@
                     }
                 }
 #endif
+                else if (strcasecmp(p->key, "bind-interfaces") == 0) {
+                    char **e, **t;
+
+                    avahi_string_list_free(c->server_config.bind_interfaces);
+                    e = avahi_split_csv(p->value);
+                    
+                    for (t = e; *t; t++) {
+                        c->server_config.bind_interfaces = 
avahi_string_list_add(c->server_config.bind_interfaces, *t);
+                    }
+                    
+                    avahi_strfreev(e);
+                    /* TODO: duplicates? */
+                    }
                 else {
                     avahi_log_error("Invalid configuration key \"%s\" in group 
\"%s\"\n", p->key, g->name);
                     goto finish;
Index: avahi-core/iface.c
===================================================================
--- avahi-core/iface.c  (revision 1781)
+++ avahi-core/iface.c  (working copy)
@@ -632,10 +632,10 @@
     return 0;
 }
 
-int avahi_interface_is_relevant(AvahiInterface *i) {
+static int avahi_interface_is_relevant_iter(AvahiInterface *i) {
     AvahiInterfaceAddress *a;
     
-    assert(i);
+    assert(i); // Not really required
 
     if (!i->hardware->flags_ok)
         return 0;
@@ -646,6 +646,23 @@
 
     return 0;
 }
+
+int avahi_interface_is_relevant(AvahiInterface *i) {
+    assert(i);
+
+    if (i->monitor->server->config.bind_interfaces != NULL) {
+        AvahiStringList *l;
+        for (l = i->monitor->server->config.bind_interfaces; l; l = l->next) {
+            if (strcasecmp((char*) l->text, i->hardware->name) == 0) {
+               return avahi_interface_is_relevant_iter(i);
+            }
+        }
+    } else {
+        return avahi_interface_is_relevant_iter(i);
+    }
+
+    return 0;
+}
     
 int avahi_interface_address_is_relevant(AvahiInterfaceAddress *a) {
     AvahiInterfaceAddress *b;
Index: avahi-core/core.h
===================================================================
--- avahi-core/core.h   (revision 1781)
+++ avahi-core/core.h   (working copy)
@@ -47,6 +47,7 @@
     char *domain_name;                /**< Default domain name. If left empty 
defaults to .local */
     int use_ipv4;                     /**< Enable IPv4 support */
     int use_ipv6;                     /**< Enable IPv6 support */
+    AvahiStringList *bind_interfaces; /**< Bind to specific interfaces */
     int publish_hinfo;                /**< Register a HINFO record for the 
host containing the local OS and CPU type */
     int publish_addresses;            /**< Register A, AAAA and PTR records 
for all local IP addresses */
     int publish_workstation;          /**< Register a _workstation._tcp 
service */
Index: avahi-core/server.c
===================================================================
--- avahi-core/server.c (revision 1781)
+++ avahi-core/server.c (working copy)
@@ -1562,6 +1562,7 @@
     memset(c, 0, sizeof(AvahiServerConfig));
     c->use_ipv6 = 1;
     c->use_ipv4 = 1;
+    c->bind_interfaces = NULL;
     c->host_name = NULL;
     c->domain_name = NULL;
     c->check_response_ttl = 0;
@@ -1595,7 +1596,7 @@
 
 AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const 
AvahiServerConfig *c) {
     char *d = NULL, *h = NULL;
-    AvahiStringList *l = NULL;
+    AvahiStringList *l = NULL, *b = NULL;
     assert(ret);
     assert(c);
 
@@ -1614,11 +1615,19 @@
         avahi_free(d);
         return NULL;
     }
+
+    if (!(b = avahi_string_list_copy(c->bind_interfaces)) && 
c->bind_interfaces) {
+        avahi_string_list_free(l);
+        avahi_free(h);
+        avahi_free(d);
+        return NULL;
+    }
     
     *ret = *c;
     ret->host_name = h;
     ret->domain_name = d;
     ret->browse_domains = l;
+    ret->bind_interfaces = b;
 
     return ret;
 }
_______________________________________________
avahi mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/avahi

Reply via email to