[gssdp] Accept messages from other networks on loopback



commit dd001ff917fbec59e8df79f1ff3a5f6baed72b75
Author: Jussi Kukkonen <jku goto fi>
Date:   Wed Jul 30 11:35:52 2014 +0300

    Accept messages from other networks on loopback
    
    Kernel does smart things and routes traffic sent to other networks
    through loopback. We need to accept messages like that.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733851

 libgssdp/gssdp-client.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/libgssdp/gssdp-client.c b/libgssdp/gssdp-client.c
index 0fc7831..71b486a 100644
--- a/libgssdp/gssdp-client.c
+++ b/libgssdp/gssdp-client.c
@@ -91,6 +91,9 @@ typedef unsigned long in_addr_t;
 /* Size of the buffer used for reading from the socket */
 #define BUF_SIZE 65536
 
+/* interface index for loopback device */
+#define LOOPBACK_IFINDEX 1
+
 static void
 gssdp_client_initable_iface_init (gpointer g_iface,
                                   gpointer iface_data);
@@ -1165,14 +1168,20 @@ socket_source_cb (GSSDPSocketSource *socket_source, GSSDPClient *client)
                 int i;
                 for (i = 0; i < num_messages; i++) {
                         GSSDPPktinfoMessage *msg;
+                        gint msg_ifindex;
+
                         if (!GSSDP_IS_PKTINFO_MESSAGE (messages[i]))
                                 continue;
 
                         msg = GSSDP_PKTINFO_MESSAGE (messages[i]);
-                        if (!((gssdp_pktinfo_message_get_ifindex (msg) ==
-                                                        client->priv->device.index) &&
-                                                (g_inet_address_equal (gssdp_pktinfo_message_get_local_addr 
(msg),
-                                                                       client->priv->device.host_addr))))
+                        msg_ifindex = gssdp_pktinfo_message_get_ifindex (msg);
+                        /* message needs to be on correct interface or on
+                         * loopback (as kernel can be smart and route things
+                         * there even if sent to another network) */
+                        if (!((msg_ifindex == client->priv->device.index ||
+                               msg_ifindex == LOOPBACK_IFINDEX) &&
+                              (g_inet_address_equal (gssdp_pktinfo_message_get_local_addr (msg),
+                                                     client->priv->device.host_addr))))
                                 goto out;
                         else
                                 break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]