X-Git-Url: http://git.meshlink.io/?p=catta;a=blobdiff_plain;f=src%2Fiface-linux.c;h=a3dc769a4f0df966d9c7aa6f6af6b88f05e18d6a;hp=4ee5b1698f9d6725bcfeaac4164c0ab62e291db8;hb=2c550daf4ac6a6aab7f21047c037b4dd53c57fa6;hpb=37d19f15523b6fe4d1fef2329abe421221b3d4b3 diff --git a/src/iface-linux.c b/src/iface-linux.c index 4ee5b16..a3dc769 100644 --- a/src/iface-linux.c +++ b/src/iface-linux.c @@ -1,18 +1,18 @@ /*** - This file is part of avahi. + This file is part of catta. - avahi is free software; you can redistribute it and/or modify it + catta 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 + catta 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 + License along with catta; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -26,9 +26,9 @@ #include #include -#include +#include -#include +#include #include "iface.h" #include "iface-linux.h" @@ -42,7 +42,7 @@ #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg)))) #endif -static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq) { +static int netlink_list_items(CattaNetlink *nl, uint16_t type, unsigned *ret_seq) { struct nlmsghdr *n; struct rtgenmsg *gen; uint8_t req[1024]; @@ -60,11 +60,11 @@ static int netlink_list_items(AvahiNetlink *nl, uint16_t type, unsigned *ret_seq memset(gen, 0, sizeof(struct rtgenmsg)); gen->rtgen_family = AF_UNSPEC; - return avahi_netlink_send(nl, n, ret_seq); + return catta_netlink_send(nl, n, ret_seq); } -static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdata) { - AvahiInterfaceMonitor *m = userdata; +static void netlink_callback(CattaNetlink *nl, struct nlmsghdr *n, void* userdata) { + CattaInterfaceMonitor *m = userdata; /* This routine is called for every RTNETLINK response packet */ @@ -77,7 +77,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat /* A new interface appeared or an existing one has been modified */ struct ifinfomsg *ifinfomsg = NLMSG_DATA(n); - AvahiHwInterface *hw; + CattaHwInterface *hw; struct rtattr *a = NULL; size_t l; @@ -85,19 +85,19 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat if (ifinfomsg->ifi_family != AF_UNSPEC) return; - /* Check whether there already is an AvahiHwInterface object + /* Check whether there already is an CattaHwInterface object * for this link, so that we can update its data. Note that * Netlink sends us an RTM_NEWLINK not only when a new * interface appears, but when it changes, too */ - if (!(hw = avahi_interface_monitor_get_hw_interface(m, ifinfomsg->ifi_index))) + if (!(hw = catta_interface_monitor_get_hw_interface(m, ifinfomsg->ifi_index))) /* No object found, so let's create a new - * one. avahi_hw_interface_new() will call - * avahi_interface_new() internally twice for IPv4 and + * one. catta_hw_interface_new() will call + * catta_interface_new() internally twice for IPv4 and * IPv6, so there is no need for us to do that * ourselves */ - if (!(hw = avahi_hw_interface_new(m, (AvahiIfIndex) ifinfomsg->ifi_index))) + if (!(hw = catta_hw_interface_new(m, (CattaIfIndex) ifinfomsg->ifi_index))) return; /* OOM */ /* Check whether the flags of this interface are OK for us */ @@ -117,8 +117,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat case IFLA_IFNAME: /* Fill in interface name */ - avahi_free(hw->name); - hw->name = avahi_strndup(RTA_DATA(a), RTA_PAYLOAD(a)); + catta_free(hw->name); + hw->name = catta_strndup(RTA_DATA(a), RTA_PAYLOAD(a)); break; case IFLA_MTU: @@ -132,8 +132,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_MAC_ADDRESS_MAX) - hw->mac_address_size = AVAHI_MAC_ADDRESS_MAX; + if (hw->mac_address_size > CATTA_MAC_ADDRESS_MAX) + hw->mac_address_size = CATTA_MAC_ADDRESS_MAX; memcpy(hw->mac_address, RTA_DATA(a), hw->mac_address_size); break; @@ -146,56 +146,56 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat } /* Check whether this interface is now "relevant" for us. If - * it is Avahi will start to announce its records on this + * it is Catta will start to announce its records on this * interface and send out queries for subscribed records on * it */ - avahi_hw_interface_check_relevant(hw); + catta_hw_interface_check_relevant(hw); /* Update any associated RRs of this interface. (i.e. the * _workstation._tcp record containing the MAC address) */ - avahi_hw_interface_update_rrs(hw, 0); + catta_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; + CattaHwInterface *hw; /* A (superfluous?) sanity check */ if (ifinfomsg->ifi_family != AF_UNSPEC) return; - /* Get a reference to our AvahiHwInterface object of this interface */ - if (!(hw = avahi_interface_monitor_get_hw_interface(m, (AvahiIfIndex) ifinfomsg->ifi_index))) + /* Get a reference to our CattaHwInterface object of this interface */ + if (!(hw = catta_interface_monitor_get_hw_interface(m, (CattaIfIndex) ifinfomsg->ifi_index))) return; /* Free our object */ - avahi_hw_interface_free(hw, 0); + catta_hw_interface_free(hw, 0); } 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; + CattaInterface *i; struct rtattr *a = NULL; size_t l; - AvahiAddress raddr, rlocal, *r; + CattaAddress raddr, rlocal, *r; int raddr_valid = 0, rlocal_valid = 0; /* We are only interested in IPv4 and IPv6 */ if (ifaddrmsg->ifa_family != AF_INET && ifaddrmsg->ifa_family != AF_INET6) return; - /* Try to get a reference to our AvahiInterface object for the + /* Try to get a reference to our CattaInterface object for the * interface this address is assigned to. If ther is no object * for this interface, we ignore this address. */ - if (!(i = avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifaddrmsg->ifa_index, avahi_af_to_proto(ifaddrmsg->ifa_family)))) + if (!(i = catta_interface_monitor_get_interface(m, (CattaIfIndex) ifaddrmsg->ifa_index, catta_af_to_proto(ifaddrmsg->ifa_family)))) return; /* Fill in address family for our new address */ - rlocal.proto = raddr.proto = avahi_af_to_proto(ifaddrmsg->ifa_family); + rlocal.proto = raddr.proto = catta_af_to_proto(ifaddrmsg->ifa_family); l = NLMSG_PAYLOAD(n, sizeof(struct ifaddrmsg)); a = IFA_RTA(ifaddrmsg); @@ -206,8 +206,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat case IFA_ADDRESS: - if ((rlocal.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || - (rlocal.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4)) + if ((rlocal.proto == CATTA_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || + (rlocal.proto == CATTA_PROTO_INET && RTA_PAYLOAD(a) != 4)) return; memcpy(rlocal.data.data, RTA_DATA(a), RTA_PAYLOAD(a)); @@ -223,8 +223,8 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat * link while IFA_ADDRESS refers to the other * end. */ - if ((raddr.proto == AVAHI_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || - (raddr.proto == AVAHI_PROTO_INET && RTA_PAYLOAD(a) != 4)) + if ((raddr.proto == CATTA_PROTO_INET6 && RTA_PAYLOAD(a) != 16) || + (raddr.proto == CATTA_PROTO_INET && RTA_PAYLOAD(a) != 4)) return; memcpy(raddr.data.data, RTA_DATA(a), RTA_PAYLOAD(a)); @@ -248,38 +248,38 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat return; if (n->nlmsg_type == RTM_NEWADDR) { - AvahiInterfaceAddress *addr; + CattaInterfaceAddress *addr; /* This address is new or has been modified, so let's get an object for it */ - if (!(addr = avahi_interface_monitor_get_address(m, i, r))) + if (!(addr = catta_interface_monitor_get_address(m, i, r))) /* Mmm, no object existing yet, so let's create a new one */ - if (!(addr = avahi_interface_address_new(m, i, r, ifaddrmsg->ifa_prefixlen))) + if (!(addr = catta_interface_address_new(m, i, r, ifaddrmsg->ifa_prefixlen))) return; /* OOM */ /* Update the scope field for the address */ addr->global_scope = ifaddrmsg->ifa_scope == RT_SCOPE_UNIVERSE || ifaddrmsg->ifa_scope == RT_SCOPE_SITE; addr->deprecated = !!(ifaddrmsg->ifa_flags & IFA_F_DEPRECATED); } else { - AvahiInterfaceAddress *addr; + CattaInterfaceAddress *addr; assert(n->nlmsg_type == RTM_DELADDR); - /* Try to get a reference to our AvahiInterfaceAddress object for this address */ - if (!(addr = avahi_interface_monitor_get_address(m, i, r))) + /* Try to get a reference to our CattaInterfaceAddress object for this address */ + if (!(addr = catta_interface_monitor_get_address(m, i, r))) return; /* And free it */ - avahi_interface_address_free(addr); + catta_interface_address_free(addr); } - /* Avahi only considers interfaces with at least one address + /* Catta only considers interfaces with at least one address * attached relevant. Since we migh have added or removed an * address, let's have it check again whether the interface is * now relevant */ - avahi_interface_check_relevant(i); + catta_interface_check_relevant(i); /* Update any associated RRs, like A or AAAA for our new/removed address */ - avahi_interface_update_rrs(i, 0); + catta_interface_update_rrs(i, 0); } else if (n->nlmsg_type == NLMSG_DONE) { @@ -291,7 +291,7 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat * let's go on with wild dumping the addresses */ if (netlink_list_items(m->osdep.netlink, RTM_GETADDR, &m->osdep.query_addr_seq) < 0) { - avahi_log_warn("NETLINK: Failed to list addrs: %s", strerror(errno)); + catta_log_warn("NETLINK: Failed to list addrs: %s", strerror(errno)); m->osdep.list = LIST_DONE; } else @@ -299,12 +299,12 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat m->osdep.list = LIST_ADDR; } else - /* We're done. Tell avahi_interface_monitor_sync() to finish. */ + /* We're done. Tell catta_interface_monitor_sync() to finish. */ m->osdep.list = LIST_DONE; if (m->osdep.list == LIST_DONE) { - /* Only after this boolean variable has been set, Avahi + /* Only after this boolean variable has been set, Catta * will start to announce or browse on all interfaces. It * is originaly set to 0, which means that relevancy * checks and RR updates are disabled during the wild @@ -312,13 +312,13 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat m->list_complete = 1; /* So let's check if any interfaces are relevant now */ - avahi_interface_monitor_check_relevant(m); + catta_interface_monitor_check_relevant(m); /* And update all RRs attached to any interface */ - avahi_interface_monitor_update_rrs(m, 0); + catta_interface_monitor_update_rrs(m, 0); /* Tell the user that the wild dump is complete */ - avahi_log_info("Network interface enumeration completed."); + catta_log_info("Network interface enumeration completed."); } } else if (n->nlmsg_type == NLMSG_ERROR && @@ -329,11 +329,11 @@ static void netlink_callback(AvahiNetlink *nl, struct nlmsghdr *n, void* userdat * ignore it otherwise */ if (e->error) - avahi_log_warn("NETLINK: Failed to browse: %s", strerror(-e->error)); + catta_log_warn("NETLINK: Failed to browse: %s", strerror(-e->error)); } } -int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) { +int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) { assert(m); /* Initialize our own data */ @@ -345,7 +345,7 @@ int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) { * makes netlink easier to use. It will attach to the main loop * for us and call netlink_callback() whenever an event * happens. */ - if (!(m->osdep.netlink = avahi_netlink_new(m->server->poll_api, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, netlink_callback, m))) + if (!(m->osdep.netlink = catta_netlink_new(m->server->poll_api, RTMGRP_LINK|RTMGRP_IPV4_IFADDR|RTMGRP_IPV6_IFADDR, netlink_callback, m))) goto fail; /* Set the initial state. */ @@ -360,32 +360,32 @@ int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) { fail: if (m->osdep.netlink) { - avahi_netlink_free(m->osdep.netlink); + catta_netlink_free(m->osdep.netlink); m->osdep.netlink = NULL; } return -1; } -void avahi_interface_monitor_free_osdep(AvahiInterfaceMonitor *m) { +void catta_interface_monitor_free_osdep(CattaInterfaceMonitor *m) { assert(m); if (m->osdep.netlink) { - avahi_netlink_free(m->osdep.netlink); + catta_netlink_free(m->osdep.netlink); m->osdep.netlink = NULL; } } -void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { +void catta_interface_monitor_sync(CattaInterfaceMonitor *m) { assert(m); /* Let's handle netlink events until we are done with wild * dumping */ while (!m->list_complete) - if (!avahi_netlink_work(m->osdep.netlink, 1) == 0) + if (!catta_netlink_work(m->osdep.netlink, 1) == 0) break; - /* At this point Avahi knows about all local interfaces and + /* At this point Catta knows about all local interfaces and * addresses in existance. */ }