]> git.meshlink.io Git - catta/blobdiff - avahi-core/iface-linux.c
don't allow registration of address records for invalid host names according to avahi...
[catta] / avahi-core / iface-linux.c
index 64bb0aec69001a529ea660dfd29f9a1007cb3d5a..910000da214be039871a9b85416d5f626da18ae7 100644 (file)
@@ -38,6 +38,8 @@ static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq
     struct nlmsghdr *n;
     struct rtgenmsg *gen;
     uint8_t req[1024];
+
+    /* Issue a wild dump NETLINK request */
     
     memset(&req, 0, sizeof(req));
     n = (struct nlmsghdr*) req;
@@ -55,17 +57,23 @@ static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq
 
 static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdata) {
     AvahiInterfaceMonitor *m = userdata;
+
+    /* This routine is called for every RTNETLINK response packet */
     
     assert(m);
     assert(n);
     assert(m->osdep.netlink == nl);
 
     if (n->nlmsg_type == RTM_NEWLINK) {
+
+        /* A new interface appeared or an existing one has been modified */
+        
         struct ifinfomsg *ifinfomsg = NLMSG_DATA(n);
         AvahiHwInterface *hw;
         struct rtattr *a = NULL;
         size_t l;
-        
+
+        /* A (superfluous?) sanity check */
         if (ifinfomsg->ifi_family != AF_UNSPEC)
             return;
 
@@ -90,7 +98,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat
             (!m->server->config.use_iff_running || (ifinfomsg->ifi_flags & IFF_RUNNING)) &&
             !(ifinfomsg->ifi_flags & IFF_LOOPBACK) &&
             (ifinfomsg->ifi_flags & IFF_MULTICAST) &&
-            !(ifinfomsg->ifi_flags & IFF_POINTOPOINT);
+            (m->server->config.allow_point_to_point || !(ifinfomsg->ifi_flags & IFF_POINTOPOINT));
 
         /* Handle interface attributes */
         l = NLMSG_PAYLOAD(n, sizeof(struct ifinfomsg));
@@ -116,8 +124,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat
 
                     /* Fill in hardware (MAC) address */
                     hw->mac_address_size = RTA_PAYLOAD(a);
-                    if (hw->mac_address_size > AVAHI_MAX_MAC_ADDRESS)
-                        hw->mac_address_size = AVAHI_MAX_MAC_ADDRESS;
+                    if (hw->mac_address_size > AVAHI_MAC_ADDRESS_MAX)
+                        hw->mac_address_size = AVAHI_MAC_ADDRESS_MAX;
                     
                     memcpy(hw->mac_address, RTA_DATA(a), hw->mac_address_size);
                     break;
@@ -140,9 +148,13 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat
         avahi_hw_interface_update_rrs(hw, 0);
         
     } else if (n->nlmsg_type == RTM_DELLINK) {
+
+        /* An interface has been removed */
+
         struct ifinfomsg *ifinfomsg = NLMSG_DATA(n);
         AvahiHwInterface *hw;
 
+        /* A (superfluous?) sanity check */
         if (ifinfomsg->ifi_family != AF_UNSPEC)
             return;
 
@@ -155,6 +167,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat
         
     } else if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
 
+        /* An address has been added, modified or removed */
+        
         struct ifaddrmsg *ifaddrmsg = NLMSG_DATA(n);
         AvahiInterface *i;
         struct rtattr *a = NULL;
@@ -304,13 +318,13 @@ int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) {
     if (!(m->osdep.netlink = avahi_netlink_new(m->server->poll_api, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, netlink_callback, m)))
         goto fail;
 
+    /* Set the initial state. */
+    m->osdep.list = LIST_IFACE;
+
     /* Start the wild dump for the interfaces */
     if (netlink_list_items(m->osdep.netlink, RTM_GETLINK, &m->osdep.query_link_seq) < 0)
         goto fail;
 
-    /* Set the initial state. */
-    m->osdep.list = LIST_IFACE;
-
     return 0;
 
 fail:
@@ -338,10 +352,9 @@ void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) {
     /* Let's handle netlink events until we are done with wild
      * dumping */
     
-    while (m->osdep.list != LIST_DONE) {
+    while (!m->list_complete)
         if (!avahi_netlink_work(m->osdep.netlink, 1) == 0)
             break;
-    }
 
     /* At this point Avahi knows about all local interfaces and
      * addresses in existance. */