X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=iface.c;h=54a58803838307206e40ce00f06bf3d0a90c3832;hb=3bbfb70938c6b08b72a8958e5a6499a9280a7d8f;hp=d2daf407272509d10bf2024b632da005d4774902;hpb=cfc653d0fd2f58ef3f4b5ecb285d5beb5bfaacfb;p=catta diff --git a/iface.c b/iface.c index d2daf40..54a5880 100644 --- a/iface.c +++ b/iface.c @@ -17,14 +17,15 @@ static void update_address_rr(flxInterfaceMonitor *m, flxInterfaceAddress *a, in g_assert(a); if (!flx_interface_address_relevant(a) || remove) { - if (a->rr_id >= 0) { - flx_server_remove(m->server, a->rr_id); - a->rr_id = -1; + if (a->entry_group) { + flx_entry_group_free(a->entry_group); + a->entry_group = NULL; } } else { - if (a->rr_id < 0) { - a->rr_id = flx_server_get_next_id(m->server); - flx_server_add_address(m->server, a->rr_id, a->interface->hardware->index, AF_UNSPEC, FALSE, m->server->hostname, &a->address); + if (!a->entry_group) { +/* a->entry_group = flx_entry_group_new(m->server, NULL, NULL); */ +/* flx_server_add_address(m->server, a->entry_group, a->interface->hardware->index, AF_UNSPEC, 0, NULL, &a->address); */ +/* flx_entry_group_commit(a->entry_group); */ } } } @@ -54,7 +55,9 @@ static void free_address(flxInterfaceMonitor *m, flxInterfaceAddress *a) { g_assert(a->interface); FLX_LLIST_REMOVE(flxInterfaceAddress, address, a->interface->addresses, a); - flx_server_remove(m->server, a->rr_id); + + if (a->entry_group) + flx_entry_group_free(a->entry_group); g_free(a); } @@ -155,6 +158,7 @@ static void new_interface(flxInterfaceMonitor *m, flxHwInterface *hw, guchar pro static void check_interface_relevant(flxInterfaceMonitor *m, flxInterface *i) { gboolean b; + g_assert(m); g_assert(i); @@ -163,13 +167,24 @@ static void check_interface_relevant(flxInterfaceMonitor *m, flxInterface *i) { if (b && !i->announcing) { g_message("New relevant interface %s.%i", i->hardware->name, i->protocol); + if (i->protocol == AF_INET) + flx_mdns_mcast_join_ipv4 (i->hardware->index, m->server->fd_ipv4); + if (i->protocol == AF_INET6) + flx_mdns_mcast_join_ipv6 (i->hardware->index, m->server->fd_ipv6); + i->announcing = TRUE; flx_announce_interface(m->server, i); } else if (!b && i->announcing) { g_message("Interface %s.%i no longer relevant", i->hardware->name, i->protocol); - i->announcing = FALSE; flx_goodbye_interface(m->server, i, FALSE); + + if (i->protocol == AF_INET) + flx_mdns_mcast_leave_ipv4 (i->hardware->index, m->server->fd_ipv4); + if (i->protocol == AF_INET6) + flx_mdns_mcast_leave_ipv6 (i->hardware->index, m->server->fd_ipv6); + + i->announcing = FALSE; } } @@ -310,7 +325,7 @@ static void callback(flxNetlink *nl, struct nlmsghdr *n, gpointer userdata) { addr->monitor = m; addr->address = raddr; addr->interface = i; - addr->rr_id = -1; + addr->entry_group = NULL; FLX_LLIST_PREPEND(flxInterfaceAddress, address, i->addresses, addr); } @@ -359,7 +374,7 @@ flxInterfaceMonitor *flx_interface_monitor_new(flxServer *s) { m = g_new0(flxInterfaceMonitor, 1); m->server = s; - if (!(m->netlink = flx_netlink_new(s->context, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, callback, m))) + if (!(m->netlink = flx_netlink_new(s->context, G_PRIORITY_DEFAULT-10, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, callback, m))) goto fail; m->hash_table = g_hash_table_new(g_int_hash, g_int_equal); @@ -371,7 +386,7 @@ flxInterfaceMonitor *flx_interface_monitor_new(flxServer *s) { goto fail; m->list = LIST_IFACE; - + return m; fail: @@ -379,6 +394,15 @@ fail: return NULL; } +void flx_interface_monitor_sync(flxInterfaceMonitor *m) { + g_assert(m); + + while (m->list != LIST_DONE) { + if (!flx_netlink_work(m->netlink, TRUE)) + break; + } +} + void flx_interface_monitor_free(flxInterfaceMonitor *m) { g_assert(m); @@ -447,12 +471,20 @@ void flx_interface_post_query(flxInterface *i, flxKey *key, gboolean immediately } -void flx_interface_post_response(flxInterface *i, const flxAddress *a, flxRecord *record, gboolean immediately) { +void flx_interface_post_response(flxInterface *i, const flxAddress *a, flxRecord *record, gboolean flush_cache, gboolean immediately) { g_assert(i); g_assert(record); if (flx_interface_relevant(i)) - flx_packet_scheduler_post_response(i->scheduler, a, record, immediately); + flx_packet_scheduler_post_response(i->scheduler, a, record, flush_cache, immediately); +} + +void flx_interface_post_probe(flxInterface *i, flxRecord *record, gboolean immediately) { + g_assert(i); + g_assert(record); + + if (flx_interface_relevant(i)) + flx_packet_scheduler_post_probe(i->scheduler, record, immediately); } void flx_dump_caches(flxInterfaceMonitor *m, FILE *f) {