]> git.meshlink.io Git - catta/commitdiff
* optionally, register A RR via IPv6, AAAA RR via IPv4 (Closes #62)
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2007 22:18:34 +0000 (22:18 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2007 22:18:34 +0000 (22:18 +0000)
* add new API function avahi_server_get_config()

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1365 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/announce.c
avahi-core/core.h
avahi-core/iface.c
avahi-core/server.c

index 4a87e1d273ca3886a63ee7ea303a5c130dc86bb1..a77fbb698874dedfbdd27f8c5745e4ba20899fb1 100644 (file)
@@ -498,7 +498,7 @@ void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, int send_goodbye
     assert(i);
 
     if (send_goodbye)
-        if (avahi_interface_is_relevant(i)) {
+        if (i->announcing) {
             AvahiEntry *e;
             
             for (e = s->entries; e; e = e->entries_next)
index e73abd2612b35e63b20aba6b7e2aaa1b2cd74879..c8e6fd6e85a85be10e3fd6dd1c0fc5a7d0457900 100644 (file)
@@ -63,6 +63,8 @@ typedef struct AvahiServerConfig {
     AvahiStringList *browse_domains;  /**< Additional browsing domains */
     int disable_publishing;           /**< Disable publishing of any record */
     int allow_point_to_point;         /**< Enable publishing on POINTOPOINT interfaces */
+    int publish_a_on_ipv6;            /**< Publish an IPv4 A RR on IPv6 sockets */
+    int publish_aaaa_on_ipv4;         /**< Publish an IPv4 A RR on IPv6 sockets */
 } AvahiServerConfig;
 
 /** Allocate a new mDNS responder object. */
@@ -148,6 +150,9 @@ uint32_t avahi_server_get_local_service_cookie(AvahiServer *s);
 /** Set the wide area DNS servers */
 int avahi_server_set_wide_area_servers(AvahiServer *s, const AvahiAddress *a, unsigned n);
 
+/** Return the current configuration of the server \since 0.6.17 */
+const AvahiServerConfig* avahi_server_get_config(AvahiServer *s);
+
 AVAHI_C_DECL_END
 
 #endif
index 56856189185b002afa5b4abf0739d92d2f294b83..9fc8cb3293e69463e660eec82fb080c68635bfea 100644 (file)
@@ -50,9 +50,9 @@ void avahi_interface_address_update_rrs(AvahiInterfaceAddress *a, int remove_rrs
     assert(a);
     m = a->monitor;
 
-    if (a->interface->announcing &&
-        m->list_complete &&
+    if (m->list_complete &&
         avahi_interface_address_is_relevant(a) &&
+        avahi_interface_is_relevant(a->interface) &&
         !remove_rrs &&
         m->server->config.publish_addresses &&
         (m->server->state == AVAHI_SERVER_RUNNING ||
@@ -67,11 +67,15 @@ void avahi_interface_address_update_rrs(AvahiInterfaceAddress *a, int remove_rrs
         
         if (avahi_s_entry_group_is_empty(a->entry_group)) {
             char t[AVAHI_ADDRESS_STR_MAX];
-            avahi_address_snprint(t, sizeof(t), &a->address);
+            AvahiProtocol p;
 
-            avahi_log_info("Registering new address record for %s on %s.", t, a->interface->hardware->name);
+            p = (a->interface->protocol == AVAHI_PROTO_INET && m->server->config.publish_a_on_ipv6) ||
+                (a->interface->protocol == AVAHI_PROTO_INET6 && m->server->config.publish_aaaa_on_ipv4) ? AVAHI_PROTO_UNSPEC : a->interface->protocol;
+            
+            avahi_address_snprint(t, sizeof(t), &a->address);
+            avahi_log_info("Registering new address record for %s on %s.%s.", t, a->interface->hardware->name, p == AVAHI_PROTO_UNSPEC ? "*" : avahi_proto_to_string(p));
 
-            if (avahi_server_add_address(m->server, a->entry_group, a->interface->hardware->index, a->interface->protocol, 0, NULL, &a->address) < 0) {
+            if (avahi_server_add_address(m->server, a->entry_group, a->interface->hardware->index, p, 0, NULL, &a->address) < 0) {
                 avahi_log_warn(__FILE__": avahi_server_add_address() failed: %s", avahi_strerror(m->server->error));
                 avahi_s_entry_group_free(a->entry_group);
                 a->entry_group = NULL;
@@ -171,6 +175,10 @@ static int interface_mdns_mcast_join(AvahiInterface *i, int join) {
 
     if (!!join  == !!i->mcast_joined)
         return 0;
+
+    if ((i->protocol == AVAHI_PROTO_INET6 && i->monitor->server->fd_ipv6 < 0) ||
+        (i->protocol == AVAHI_PROTO_INET && i->monitor->server->fd_ipv4 < 0))
+        return -1;
     
     if (join) {
         AvahiInterfaceAddress *a;
@@ -186,10 +194,8 @@ static int interface_mdns_mcast_join(AvahiInterface *i, int join) {
             a = i->addresses;
 
         /* Hmm, there is no address available. */
-        if (!a) {
-            avahi_log_warn(__FILE__": interface_mdns_mcast_join() called but no local address available."); 
+        if (!a)
             return -1;
-        }
 
         i->local_mcast_address = a->address;
     }
@@ -387,9 +393,9 @@ AvahiHwInterface *avahi_hw_interface_new(AvahiInterfaceMonitor *m, AvahiIfIndex
             
     avahi_hashmap_insert(m->hashmap, &hw->index, hw);
 
-    if (m->server->fd_ipv4 >= 0)
+    if (m->server->fd_ipv4 >= 0 || m->server->config.publish_a_on_ipv6)
         avahi_interface_new(m, hw, AVAHI_PROTO_INET);
-    if (m->server->fd_ipv6 >= 0)
+    if (m->server->fd_ipv6 >= 0 || m->server->config.publish_aaaa_on_ipv4)
         avahi_interface_new(m, hw, AVAHI_PROTO_INET6);
 
     return hw;
@@ -426,13 +432,16 @@ void avahi_interface_check_relevant(AvahiInterface *i) {
     b = avahi_interface_is_relevant(i);
 
     if (m->list_complete && b && !i->announcing) {
-        avahi_log_info("New relevant interface %s.%s for mDNS.", i->hardware->name, avahi_proto_to_string(i->protocol));
-
         interface_mdns_mcast_join(i, 1);
 
-        i->announcing = 1;
-        avahi_announce_interface(m->server, i);
-        avahi_multicast_lookup_engine_new_interface(m->server->multicast_lookup_engine, i);
+        if (i->mcast_joined) {
+            avahi_log_info("New relevant interface %s.%s for mDNS.", i->hardware->name, avahi_proto_to_string(i->protocol));
+
+            i->announcing = 1;
+            avahi_announce_interface(m->server, i);
+            avahi_multicast_lookup_engine_new_interface(m->server->multicast_lookup_engine, i);
+        }
+        
     } else if (!b && i->announcing) {
         avahi_log_info("Interface %s.%s no longer relevant for mDNS.", i->hardware->name, avahi_proto_to_string(i->protocol));
 
@@ -553,7 +562,7 @@ void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, c
     assert(i);
     assert(p);
 
-    if (!avahi_interface_is_relevant(i))
+    if (!i->announcing)
         return;
     
     assert(!a || a->proto == i->protocol);
@@ -575,10 +584,10 @@ int avahi_interface_post_query(AvahiInterface *i, AvahiKey *key, int immediately
     assert(i);
     assert(key);
 
-    if (avahi_interface_is_relevant(i))
-        return avahi_query_scheduler_post(i->query_scheduler, key, immediately, ret_id);
-
-    return 0;
+    if (!i->announcing)
+        return 0;
+    
+    return avahi_query_scheduler_post(i->query_scheduler, key, immediately, ret_id);
 }
 
 int avahi_interface_withraw_query(AvahiInterface *i, unsigned id) {
@@ -590,20 +599,20 @@ int avahi_interface_post_response(AvahiInterface *i, AvahiRecord *record, int fl
     assert(i);
     assert(record);
 
-    if (avahi_interface_is_relevant(i))
-        return avahi_response_scheduler_post(i->response_scheduler, record, flush_cache, querier, immediately);
-
-    return 0;
+    if (!i->announcing)
+        return 0;
+    
+    return avahi_response_scheduler_post(i->response_scheduler, record, flush_cache, querier, immediately);
 }
 
 int avahi_interface_post_probe(AvahiInterface *i, AvahiRecord *record, int immediately) {
     assert(i);
     assert(record);
     
-    if (avahi_interface_is_relevant(i))
-        return avahi_probe_scheduler_post(i->probe_scheduler, record, immediately);
+    if (!i->announcing)
+        return 0;
 
-    return 0;
+    return avahi_probe_scheduler_post(i->probe_scheduler, record, immediately);
 }
 
 int avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, void* userdata) {
@@ -625,21 +634,19 @@ int avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, void
 
 int avahi_interface_is_relevant(AvahiInterface *i) {
     AvahiInterfaceAddress *a;
-    int relevant_address;
     
     assert(i);
 
-    relevant_address = 0;
+    if (!i->hardware->flags_ok)
+        return 0;
     
     for (a = i->addresses; a; a = a->address_next)
-        if (avahi_interface_address_is_relevant(a)) {
-            relevant_address = 1;
-            break;
-        }
+        if (avahi_interface_address_is_relevant(a))
+            return 1;
 
-    return i->hardware->flags_ok && relevant_address;
+    return 0;
 }
-
+    
 int avahi_interface_address_is_relevant(AvahiInterfaceAddress *a) {
     AvahiInterfaceAddress *b;
     assert(a);
index 5bfbc5096502c090700e93a6f493bf466833cf44..952f09e1245a94dd64d73fc3d0c40606f40bb8cc 100644 (file)
@@ -803,7 +803,7 @@ static void reflect_legacy_unicast_query_packet(AvahiServer *s, AvahiDnsPacket *
     avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_ID, slot->id);
     
     for (j = s->monitor->interfaces; j; j = j->interface_next)
-        if (avahi_interface_is_relevant(j) &&
+        if (j->announcing &&
             j != i &&
             (s->config.reflect_ipv || j->protocol == i->protocol)) {
 
@@ -884,7 +884,7 @@ static void dispatch_packet(AvahiServer *s, AvahiDnsPacket *p, const AvahiAddres
     assert(src_address->proto == dst_address->proto);
 
     if (!(i = avahi_interface_monitor_get_interface(s->monitor, iface, src_address->proto)) ||
-        !avahi_interface_is_relevant(i)) {
+        !i->announcing) {
         avahi_log_warn("Recieved packet from invalid interface.");
         return;
     }
@@ -977,7 +977,7 @@ static void dispatch_legacy_unicast_packet(AvahiServer *s, AvahiDnsPacket *p) {
     }
 
     if (!(j = avahi_interface_monitor_get_interface(s->monitor, slot->interface, slot->address.proto)) ||
-        !avahi_interface_is_relevant(j))
+        !j->announcing)
         return;
 
     /* Patch the original ID into this response */
@@ -1560,6 +1560,8 @@ AvahiServerConfig* avahi_server_config_init(AvahiServerConfig *c) {
     c->browse_domains = NULL;
     c->disable_publishing = 0;
     c->allow_point_to_point = 0;
+    c->publish_aaaa_on_ipv4 = 1;
+    c->publish_a_on_ipv6 = 0;
     
     return c;
 }
@@ -1721,3 +1723,9 @@ int avahi_server_set_wide_area_servers(AvahiServer *s, const AvahiAddress *a, un
     avahi_wide_area_set_servers(s->wide_area_lookup_engine, a, n);
     return AVAHI_OK;
 }
+
+const AvahiServerConfig* avahi_server_get_config(AvahiServer *s) {
+    assert(s);
+
+    return &s->config;
+}