Please refer https://bugs.freedesktop.org/show_bug.cgi?id=51501

History ::
===========

As pointed out by Simon McVittie in https://bugs.freedesktop.org/show_bug.cgi?id=51501#c4,
https://tools.ietf.org/html/draft-cheshire-dnsext-multicastdns-15#section-10 
suggests that the Time-To-Live (TT) of the mDNS record is likely to be 120 seconds.

However, for all purposes, in whatever testing I came across Avahi, the TTL in effect was
75 minutes , which seemed a bit too late a notification of buddy-going-disconnected.



Fix ::
======
Decrease the Time-To-Live (TTL).



Solution ::
===========

Obviously, the easiest solution is to set the appropriate values in 
                  #define AVAHI_DEFAULT_TTL_HOST_NAME
		  #define AVAHI_DEFAULT_TTL

However, this has the following caveats ::

(i)
It needs a re-compilation/re-packaging of avahi rpms, for every
change in the values. This is a major deployment headache.

(ii)
Also, there is no ideal "TTL" values. 

The lesses the TTL values, more frequent multicast DNS packets will be exchanged
between a pair of peers, thus leading to more traffic.

However, too large a TTL value, would mean that the peer gets too late a notification
of the buddy going disconnected.

Thus, ideal values can only be found out by testing in real-field.
This requires easy configuration of the TTL values, without needing to 
re-compile the rpms.



Solution-Implementation ::
==========================

The cutomized TTL values will be read during "avahi-daemon" startup.

1.
AVAHI_DEFAULT_TTL_HOST_NAME will be set to the value, contained in the 
file "/etc/avahi/avahi-default-ttl-host-name.conf".

Default value is the same as before, i.e. 120 (seconds).


2.
AVAHI_DEFAULT_TTL will be set to the value, contained in the 
file "/etc/avahi/avahi-default-ttl.conf".

Default value is the same as before, i.e. 4500 (seconds), which is equal to 
75 minutes.



How to customize ::
===================

a)
"sudo service avahi-daemon stop"

b)
Change the values in the corresponding conf files.

c)
"sudo service avahi-daemon start"




AUTHOR: Ajay Garg <ajay@activitycentral.com>


Thanks to ::

    Will Thompson    <will.thompson@collabora.co.uk>
    Simon McVittie   <simon.mcvittie@collabora.co.uk>
    Xavier Claessens <xclaesse@gmail.com>
    



diff -uNr avahi-0.6.27/avahi-common/defs.h copy-avahi-0.6.27/avahi-common/defs.h
--- avahi-0.6.27/avahi-common/defs.h	2010-06-26 05:44:35.496078496 +0530
+++ copy-avahi-0.6.27/avahi-common/defs.h	2012-07-06 13:49:53.079315001 +0530
@@ -345,11 +345,14 @@
 
 /** @} */
 
+int get_avahi_default_ttl_host_name();
+int get_avahi_default_ttl();
+
 /** The default TTL for RRs which contain a host name of some kind. */
-#define AVAHI_DEFAULT_TTL_HOST_NAME (120)
+#define AVAHI_DEFAULT_TTL_HOST_NAME get_avahi_default_ttl_host_name()
 
 /** The default TTL for all other records. */
-#define AVAHI_DEFAULT_TTL (75*60)
+#define AVAHI_DEFAULT_TTL get_avahi_default_ttl()
 
 AVAHI_C_DECL_END
 
diff -uNr avahi-0.6.27/avahi-common/load_ttl_config.c copy-avahi-0.6.27/avahi-common/load_ttl_config.c
--- avahi-0.6.27/avahi-common/load_ttl_config.c	1970-01-01 05:30:00.000000000 +0530
+++ copy-avahi-0.6.27/avahi-common/load_ttl_config.c	2012-07-06 13:55:11.348315001 +0530
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+int avahi_default_ttl_host_name;
+int avahi_default_ttl;
+
+
+int read_int_from_file(const char *filename) {
+    FILE *fp = NULL;
+    char line[128];
+
+    fp = fopen(filename, "r");
+    fgets(line, 128, fp);
+    fclose(fp);
+
+    return atoi(line);
+}
+
+
+int load_default_ttl_values() {
+    avahi_default_ttl_host_name = read_int_from_file(AVAHI_DEFAULT_TTL_HOST_NAME_CONFIG_FILE);
+    avahi_default_ttl = read_int_from_file(AVAHI_DEFAULT_TTL_CONFIG_FILE);
+}
+
+
+int get_avahi_default_ttl_host_name() {
+    return avahi_default_ttl_host_name;
+}
+
+
+int get_avahi_default_ttl() {
+    return avahi_default_ttl;
+}
diff -uNr avahi-0.6.27/avahi-common/Makefile.am copy-avahi-0.6.27/avahi-common/Makefile.am
--- avahi-0.6.27/avahi-common/Makefile.am	2010-06-26 05:44:35.494078632 +0530
+++ copy-avahi-0.6.27/avahi-common/Makefile.am	2012-07-06 13:54:34.789315001 +0530
@@ -17,6 +17,12 @@
 
 AM_CFLAGS=-I$(top_srcdir)
 
+pkgsysconfdir=$(sysconfdir)/avahi
+
+AM_CFLAGS+= \
+	-DAVAHI_DEFAULT_TTL_HOST_NAME_CONFIG_FILE=\"$(pkgsysconfdir)/avahi-default-ttl-host-name.conf\" \
+	-DAVAHI_DEFAULT_TTL_CONFIG_FILE=\"$(pkgsysconfdir)/avahi-default-ttl.conf\"
+
 # This cool debug trap works on i386/gcc only
 AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
 
@@ -66,7 +72,8 @@
 	watch.h gccmacro.h \
 	rlist.h rlist.c \
 	utf8.c utf8.h \
-	i18n.c i18n.h
+	i18n.c i18n.h \
+	load_ttl_config.c
 
 libavahi_common_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -DAVAHI_LOCALEDIR=\"$(avahilocaledir)\"
 libavahi_common_la_LIBADD = $(AM_LDADD) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) $(INTLLIBS)
diff -uNr avahi-0.6.27/avahi-daemon/avahi-default-ttl.conf copy-avahi-0.6.27/avahi-daemon/avahi-default-ttl.conf
--- avahi-0.6.27/avahi-daemon/avahi-default-ttl.conf	1970-01-01 05:30:00.000000000 +0530
+++ copy-avahi-0.6.27/avahi-daemon/avahi-default-ttl.conf	2012-07-06 13:49:53.059315001 +0530
@@ -0,0 +1 @@
+4500
diff -uNr avahi-0.6.27/avahi-daemon/avahi-default-ttl-host-name.conf copy-avahi-0.6.27/avahi-daemon/avahi-default-ttl-host-name.conf
--- avahi-0.6.27/avahi-daemon/avahi-default-ttl-host-name.conf	1970-01-01 05:30:00.000000000 +0530
+++ copy-avahi-0.6.27/avahi-daemon/avahi-default-ttl-host-name.conf	2012-07-06 13:49:53.060315001 +0530
@@ -0,0 +1 @@
+120
diff -uNr avahi-0.6.27/avahi-daemon/main.c copy-avahi-0.6.27/avahi-daemon/main.c
--- avahi-0.6.27/avahi-daemon/main.c	2010-07-13 06:27:19.331756055 +0530
+++ copy-avahi-0.6.27/avahi-daemon/main.c	2012-07-06 13:49:53.058315001 +0530
@@ -581,6 +581,8 @@
     AvahiIniFile *f;
     AvahiIniFileGroup *g;
 
+    load_default_ttl_values();
+
     assert(c);
 
     if (!(f = avahi_ini_file_load(c->config_file ? c->config_file : AVAHI_CONFIG_FILE)))
diff -uNr avahi-0.6.27/avahi-daemon/Makefile.am copy-avahi-0.6.27/avahi-daemon/Makefile.am
--- avahi-0.6.27/avahi-daemon/Makefile.am	2010-06-27 04:21:50.566291478 +0530
+++ copy-avahi-0.6.27/avahi-daemon/Makefile.am	2012-07-06 13:49:53.056315001 +0530
@@ -67,6 +67,8 @@
 
 pkgsysconf_DATA = \
 	avahi-daemon.conf \
+	avahi-default-ttl-host-name.conf \
+	avahi-default-ttl.conf \
 	hosts
 
 dist_service_DATA = \
@@ -154,6 +156,8 @@
 
 EXTRA_DIST = \
 	avahi-daemon.conf \
+	avahi-default-ttl-host-name.conf \
+	avahi-default-ttl.conf \
 	example.service \
 	hosts \
 	example.service \
