summaryrefslogtreecommitdiffstats
path: root/avahi-core/iface.h
blob: 47c54bad5f54285f006b836b54b6d2f4a35e4807 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef fooifacehfoo
#define fooifacehfoo

/* $Id$ */

/***
  This file is part of avahi.
 
  avahi is free software; you can redistribute it and/or modify it
  under the terms of the GNU Lesser General Public License as
  published by the Free Software Foundation; either version 2.1 of the
  License, or (at your option) any later version.
 
  avahi is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
  Public License for more details.
 
  You should have received a copy of the GNU Lesser General Public
  License along with avahi; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA.
***/

#include <glib.h>

typedef struct AvahiInterfaceMonitor AvahiInterfaceMonitor;
typedef struct AvahiInterfaceAddress AvahiInterfaceAddress;
typedef struct AvahiInterface AvahiInterface;
typedef struct AvahiHwInterface AvahiHwInterface;

#include <avahi-common/llist.h>
#include <avahi-common/address.h>
#include "server.h"
#include "netlink.h"
#include "cache.h"
#include "response-sched.h"
#include "query-sched.h"
#include "probe-sched.h"
#include "dns.h"
#include "announce.h"

#define AVAHI_MAX_MAC_ADDRESS 32

struct AvahiInterfaceMonitor {
    AvahiServer *server;
    AvahiNetlink *netlink;
    GHashTable *hash_table;

    AVAHI_LLIST_HEAD(AvahiInterface, interfaces);
    AVAHI_LLIST_HEAD(AvahiHwInterface, hw_interfaces);
    
    guint query_addr_seq, query_link_seq;
    
    enum {
        LIST_IFACE,
        LIST_ADDR,
        LIST_DONE
    } list;
};

struct AvahiHwInterface {
    AVAHI_LLIST_FIELDS(AvahiHwInterface, hardware);
    AvahiInterfaceMonitor *monitor;

    gchar *name;
    AvahiIfIndex index;
    guint flags;
    guint mtu;

    guint8 mac_address[AVAHI_MAX_MAC_ADDRESS];
    guint mac_address_size;

    AvahiEntryGroup *entry_group;

    AVAHI_LLIST_HEAD(AvahiInterface, interfaces);
};

struct AvahiInterface {
    AVAHI_LLIST_FIELDS(AvahiInterface, interface);
    AVAHI_LLIST_FIELDS(AvahiInterface, by_hardware);
    AvahiInterfaceMonitor *monitor;
    
    AvahiHwInterface *hardware;
    AvahiProtocol protocol;
    gboolean announcing;

    AvahiCache *cache;
    AvahiQueryScheduler *query_scheduler;
    AvahiResponseScheduler * response_scheduler;
    AvahiProbeScheduler *probe_scheduler;

    AVAHI_LLIST_HEAD(AvahiInterfaceAddress, addresses);
    AVAHI_LLIST_HEAD(AvahiAnnouncement, announcements);
};

struct AvahiInterfaceAddress {
    AVAHI_LLIST_FIELDS(AvahiInterfaceAddress, address);
    AvahiInterfaceMonitor *monitor;
    
    guchar flags;
    guchar scope;
    guchar prefix_len;
    AvahiAddress address;
    
    AvahiEntryGroup *entry_group;
    AvahiInterface *interface;
};

AvahiInterfaceMonitor *avahi_interface_monitor_new(AvahiServer *server);
void avahi_interface_monitor_free(AvahiInterfaceMonitor *m);

void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m);

AvahiInterface* avahi_interface_monitor_get_interface(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol);
AvahiHwInterface* avahi_interface_monitor_get_hw_interface(AvahiInterfaceMonitor *m, gint idx);

void avahi_interface_send_packet(AvahiInterface *i, AvahiDnsPacket *p);
void avahi_interface_send_packet_unicast(AvahiInterface *i, AvahiDnsPacket *p, const AvahiAddress *a, guint16 port);

gboolean avahi_interface_post_query(AvahiInterface *i, AvahiKey *k, gboolean immediately);
gboolean avahi_interface_post_response(AvahiInterface *i, AvahiRecord *record, gboolean flush_cache, const AvahiAddress *querier, gboolean immediately);
gboolean avahi_interface_post_probe(AvahiInterface *i, AvahiRecord *p, gboolean immediately);

void avahi_dump_caches(AvahiInterfaceMonitor *m, AvahiDumpCallback callback, gpointer userdata);

gboolean avahi_interface_relevant(AvahiInterface *i);
gboolean avahi_interface_address_relevant(AvahiInterfaceAddress *a);

gboolean avahi_interface_match(AvahiInterface *i, AvahiIfIndex idx, AvahiProtocol protocol);

typedef void (*AvahiInterfaceMonitorWalkCallback)(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata);
    
void avahi_interface_monitor_walk(AvahiInterfaceMonitor *m, AvahiIfIndex idx, AvahiProtocol protocol, AvahiInterfaceMonitorWalkCallback callback, gpointer userdata);

void avahi_update_host_rrs(AvahiInterfaceMonitor *m, gboolean remove_rrs);

gboolean avahi_address_is_local(AvahiInterfaceMonitor *m, const AvahiAddress *a);

gboolean avahi_interface_address_on_link(AvahiInterface *i, const AvahiAddress *a);


#endif