[avahi] [PATCH] Publish service per interface from .service

Charles_Claggett at Dell.com Charles_Claggett at Dell.com
Wed Aug 12 14:16:43 PDT 2015


Dell Customer Communication
Greetings,

We would like to add to the Avahi service file functionality by adding an "interface" attribute to restrict mDNS announcements on a per interface basis. This would allow a system with multiple interfaces and/or vlans to only advertise certain services on certain network paths.

If the service file does not contain the new attribute, Avahi still performs the existing behavior of publishing on all interfaces.

[PATCH]
Description: Add interface attribute for Avahi service files. If present,
the service or sub-type will publish only on the specified interface. If
not present the default behavior of publishing on all interfaces is unchanged.
The value for this attribute is the system ifname. If the interface is invalid,
the service is not published and an error is logged.


Author: Charles_Claggett at dell.com
Index: 0.6.31-r11.1/avahi-0.6.31/avahi-daemon/static-services.c
===================================================================
--- 0.6.31-r11.1.orig/avahi-0.6.31/avahi-daemon/static-services.c
+++ 0.6.31-r11.1/avahi-0.6.31/avahi-daemon/static-services.c
@@ -21,6 +21,7 @@
#include <config.h>
#endif
+#include <net/if.h>
#include <sys/stat.h>
#include <glob.h>
#include <limits.h>
@@ -60,6 +61,7 @@ struct StaticService {
     char *host_name;
     uint16_t port;
     int protocol;
+    int interface;
     AvahiStringList *subtypes;
@@ -122,6 +124,7 @@ static StaticService *static_service_new
     s->type = s->host_name = s->domain_name = NULL;
     s->port = 0;
+    s->interface = AVAHI_IF_UNSPEC;
     s->protocol = AVAHI_PROTO_UNSPEC;
     s->txt_records = NULL;
@@ -256,7 +259,7 @@ static void add_static_service_group_to_
         if (avahi_server_add_service_strlst(
                 avahi_server,
                 g->entry_group,
-                AVAHI_IF_UNSPEC, s->protocol,
+                s->interface, s->protocol,
                 0,
                 g->chosen_name, s->type, s->domain_name,
                 s->host_name, s->port,
@@ -273,7 +276,7 @@ static void add_static_service_group_to_
             if (avahi_server_add_service_subtype(
                     avahi_server,
                    g->entry_group,
-                    AVAHI_IF_UNSPEC, s->protocol,
+                    s->interface, s->protocol,
                     0,
                     g->chosen_name, s->type, s->domain_name,
                     (char*) i->text) < 0) {
@@ -305,6 +308,7 @@ typedef enum {
     XML_TAG_DOMAIN_NAME,
     XML_TAG_HOST_NAME,
     XML_TAG_PORT,
+    XML_TAG_INTERFACE,
     XML_TAG_TXT_RECORD
} xml_tag_name;
@@ -402,6 +406,11 @@ static void XMLCALL xml_start(void *data
             goto invalid_attr;
         u->current_tag = XML_TAG_PORT;
+    } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "interface") == 0) {
+        if (attr[0])
+            goto invalid_attr;
+
+        u->current_tag = XML_TAG_INTERFACE;
     } else if (u->current_tag == XML_TAG_SERVICE && strcmp(el, "txt-record") == 0) {
         if (attr[0])
             goto invalid_attr;
@@ -473,6 +482,23 @@ static void XMLCALL xml_end(void *data,
             break;
         }
+        case XML_TAG_INTERFACE: {
+            int interface;
+            assert(u->service);
+
+            interface = (int) if_nametoindex(u->buf);
+
+            if(interface < 1) {
+                avahi_log_error("%s: parse failure: invalid interface specification \"%s\".", u->group->filename, u->buf);
+                u->failed = 1;
+                return;
+            }
+
+            u->service->interface = interface;
+
+            u->current_tag = XML_TAG_SERVICE;
+            break;
+        }
         case XML_TAG_TXT_RECORD: {
             assert(u->service);
@@ -550,6 +576,7 @@ static void XMLCALL xml_cdata(void *data
             break;
         case XML_TAG_PORT:
+        case XML_TAG_INTERFACE:
         case XML_TAG_TXT_RECORD:
         case XML_TAG_SUBTYPE:
             assert(u->service);



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/avahi/attachments/20150812/e3a123a1/attachment.html>


More information about the avahi mailing list