X-Git-Url: http://git.meshlink.io/?p=catta;a=blobdiff_plain;f=src%2Fiface-pfroute.c;h=3db53a38a1f5238b664b85810ad821e262ef4033;hp=34c90fa068f70292192bf87032b530c2877304b0;hb=2c550daf4ac6a6aab7f21047c037b4dd53c57fa6;hpb=37d19f15523b6fe4d1fef2329abe421221b3d4b3 diff --git a/src/iface-pfroute.c b/src/iface-pfroute.c index 34c90fa..3db53a3 100644 --- a/src/iface-pfroute.c +++ b/src/iface-pfroute.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. ***/ @@ -21,7 +21,7 @@ #include #endif -#include +#include #include #include @@ -41,7 +41,7 @@ #include #include -#include +#include #include "iface.h" #include "iface-pfroute.h" #include "util.h" @@ -57,9 +57,9 @@ static int bitcount (unsigned int n) return count ; } -static void rtm_info(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) +static void rtm_info(struct rt_msghdr *rtm, CattaInterfaceMonitor *m) { - AvahiHwInterface *hw; + CattaHwInterface *hw; struct if_msghdr *ifm = (struct if_msghdr *)rtm; struct sockaddr_dl *sdl = (struct sockaddr_dl *)(ifm + 1); @@ -67,14 +67,14 @@ static void rtm_info(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) return; if (ifm->ifm_addrs == 0 && ifm->ifm_index > 0) { - if (!(hw = avahi_interface_monitor_get_hw_interface(m, (AvahiIfIndex) ifm->ifm_index))) + if (!(hw = catta_interface_monitor_get_hw_interface(m, (CattaIfIndex) ifm->ifm_index))) return; - avahi_hw_interface_free(hw, 0); + catta_hw_interface_free(hw, 0); return; } - if (!(hw = avahi_interface_monitor_get_hw_interface(m, ifm->ifm_index))) - if (!(hw = avahi_hw_interface_new(m, (AvahiIfIndex) ifm->ifm_index))) + if (!(hw = catta_interface_monitor_get_hw_interface(m, ifm->ifm_index))) + if (!(hw = catta_hw_interface_new(m, (CattaIfIndex) ifm->ifm_index))) return; /* OOM */ hw->flags_ok = @@ -84,28 +84,28 @@ static void rtm_info(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) (ifm->ifm_flags & IFF_MULTICAST) && (m->server->config.allow_point_to_point || !(ifm->ifm_flags & IFF_POINTOPOINT)); - avahi_free(hw->name); - hw->name = avahi_strndup(sdl->sdl_data, sdl->sdl_nlen); + catta_free(hw->name); + hw->name = catta_strndup(sdl->sdl_data, sdl->sdl_nlen); hw->mtu = ifm->ifm_data.ifi_mtu; hw->mac_address_size = sdl->sdl_alen; - 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, sdl->sdl_data + sdl->sdl_nlen, hw->mac_address_size); /* { */ /* char mac[256]; */ -/* avahi_log_debug("======\n name: %s\n index:%d\n mtu:%d\n mac:%s\n flags_ok:%d\n======", */ +/* catta_log_debug("======\n name: %s\n index:%d\n mtu:%d\n mac:%s\n flags_ok:%d\n======", */ /* hw->name, hw->index, */ /* hw->mtu, */ -/* avahi_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size), */ +/* catta_format_mac_address(mac, sizeof(mac), hw->mac_address, hw->mac_address_size), */ /* hw->flags_ok); */ /* } */ - avahi_hw_interface_check_relevant(hw); - avahi_hw_interface_update_rrs(hw, 0); + catta_hw_interface_check_relevant(hw); + catta_hw_interface_update_rrs(hw, 0); } #define ROUNDUP(a) \ @@ -116,10 +116,10 @@ static void rtm_info(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) #define ADVANCE(x, n) (x += ROUNDUP(sizeof(struct sockaddr))) #endif -static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) +static void rtm_addr(struct rt_msghdr *rtm, CattaInterfaceMonitor *m) { - AvahiInterface *iface; - AvahiAddress raddr; + CattaInterface *iface; + CattaAddress raddr; int raddr_valid = 0; struct ifa_msghdr *ifam = (struct ifa_msghdr *) rtm; char *cp = (char *)(ifam + 1); @@ -149,10 +149,10 @@ static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) if(sa->sa_family != AF_INET && sa->sa_family != AF_INET6) return; - if (!(iface = avahi_interface_monitor_get_interface(m, (AvahiIfIndex) ifam->ifam_index, avahi_af_to_proto(sa->sa_family)))) + if (!(iface = catta_interface_monitor_get_interface(m, (CattaIfIndex) ifam->ifam_index, catta_af_to_proto(sa->sa_family)))) return; - raddr.proto = avahi_af_to_proto(sa->sa_family); + raddr.proto = catta_af_to_proto(sa->sa_family); for(cp = cp0, i = 0; i < RTAX_MAX; i++) { @@ -210,11 +210,11 @@ static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) if(rtm->rtm_type == RTM_NEWADDR) { - AvahiInterfaceAddress *addriface; - if (!(addriface = avahi_interface_monitor_get_address(m, iface, &raddr))) - if (!(addriface = avahi_interface_address_new(m, iface, &raddr, prefixlen))) + CattaInterfaceAddress *addriface; + if (!(addriface = catta_interface_monitor_get_address(m, iface, &raddr))) + if (!(addriface = catta_interface_address_new(m, iface, &raddr, prefixlen))) return; /* OOM */ - if (raddr.proto == AVAHI_PROTO_INET6) + if (raddr.proto == CATTA_PROTO_INET6) { addriface->global_scope = !(IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)raddr.data.data) || IN6_IS_ADDR_MULTICAST((struct in6_addr *)raddr.data.data)); } @@ -223,24 +223,24 @@ static void rtm_addr(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) } else { - AvahiInterfaceAddress *addriface; + CattaInterfaceAddress *addriface; assert(rtm->rtm_type == RTM_DELADDR); - if (!(addriface = avahi_interface_monitor_get_address(m, iface, &raddr))) + if (!(addriface = catta_interface_monitor_get_address(m, iface, &raddr))) return; - avahi_interface_address_free(addriface); + catta_interface_address_free(addriface); } - avahi_interface_check_relevant(iface); - avahi_interface_update_rrs(iface, 0); + catta_interface_check_relevant(iface); + catta_interface_update_rrs(iface, 0); } -static void parse_rtmsg(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) +static void parse_rtmsg(struct rt_msghdr *rtm, CattaInterfaceMonitor *m) { assert(m); assert(rtm); if (rtm->rtm_version != RTM_VERSION) { - avahi_log_warn("routing message version %d not understood", + catta_log_warn("routing message version %d not understood", rtm->rtm_version); return; } @@ -258,9 +258,9 @@ static void parse_rtmsg(struct rt_msghdr *rtm, AvahiInterfaceMonitor *m) } } -static void socket_event(AvahiWatch *w, int fd, AVAHI_GCC_UNUSED AvahiWatchEvent event,void *userdata) { - AvahiInterfaceMonitor *m = (AvahiInterfaceMonitor *)userdata; - AvahiPfRoute *nl = m->osdep.pfroute; +static void socket_event(CattaWatch *w, int fd, CATTA_GCC_UNUSED CattaWatchEvent event,void *userdata) { + CattaInterfaceMonitor *m = (CattaInterfaceMonitor *)userdata; + CattaPfRoute *nl = m->osdep.pfroute; ssize_t bytes; char msg[2048]; @@ -273,7 +273,7 @@ static void socket_event(AvahiWatch *w, int fd, AVAHI_GCC_UNUSED AvahiWatchEvent if((bytes = recv(nl->fd, msg, 2048, MSG_DONTWAIT)) < 0) { if (errno == EAGAIN || errno == EINTR) return; - avahi_log_error(__FILE__": recv() failed: %s", strerror(errno)); + catta_log_error(__FILE__": recv() failed: %s", strerror(errno)); return; } parse_rtmsg((struct rt_msghdr *)msg, m); @@ -281,7 +281,7 @@ static void socket_event(AvahiWatch *w, int fd, AVAHI_GCC_UNUSED AvahiWatchEvent while (bytes > 0); } -int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) { +int catta_interface_monitor_init_osdep(CattaInterfaceMonitor *m) { int fd = -1; assert(m); @@ -289,22 +289,22 @@ int avahi_interface_monitor_init_osdep(AvahiInterfaceMonitor *m) { m->osdep.pfroute = NULL; if ((fd = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC)) < 0) { - avahi_log_error(__FILE__": socket(PF_ROUTE): %s", strerror(errno)); + catta_log_error(__FILE__": socket(PF_ROUTE): %s", strerror(errno)); goto fail; } - if (!(m->osdep.pfroute = avahi_new(AvahiPfRoute , 1))) { - avahi_log_error(__FILE__": avahi_new() failed."); + if (!(m->osdep.pfroute = catta_new(CattaPfRoute , 1))) { + catta_log_error(__FILE__": catta_new() failed."); goto fail; } m->osdep.pfroute->fd = fd; if (!(m->osdep.pfroute->watch = m->server->poll_api->watch_new(m->server->poll_api, m->osdep.pfroute->fd, - AVAHI_WATCH_IN, + CATTA_WATCH_IN, socket_event, m))) { - avahi_log_error(__FILE__": Failed to create watch."); + catta_log_error(__FILE__": Failed to create watch."); goto fail; } @@ -325,7 +325,7 @@ fail: return -1; } -void avahi_interface_monitor_free_osdep(AvahiInterfaceMonitor *m) { +void catta_interface_monitor_free_osdep(CattaInterfaceMonitor *m) { assert(m); if (m->osdep.pfroute) { @@ -335,7 +335,7 @@ void avahi_interface_monitor_free_osdep(AvahiInterfaceMonitor *m) { if (m->osdep.pfroute->fd >= 0) close(m->osdep.pfroute->fd); - avahi_free(m->osdep.pfroute); + catta_free(m->osdep.pfroute); m->osdep.pfroute = NULL; } } @@ -366,42 +366,42 @@ static int ip6_masklen (struct in6_addr netmask) { return len; } -static void if_add_interface(struct lifreq *lifreq, AvahiInterfaceMonitor *m, int fd, int count) +static void if_add_interface(struct lifreq *lifreq, CattaInterfaceMonitor *m, int fd, int count) { - AvahiHwInterface *hw; - AvahiAddress addr; + CattaHwInterface *hw; + CattaAddress addr; struct lifreq lifrcopy; unsigned int index; int flags; int mtu; int prefixlen; - AvahiInterfaceAddress *addriface; - AvahiInterface *iface; + CattaInterfaceAddress *addriface; + CattaInterface *iface; struct sockaddr_in mask; struct sockaddr_in6 mask6; - char caddr[AVAHI_ADDRESS_STR_MAX]; + char caddr[CATTA_ADDRESS_STR_MAX]; lifrcopy = *lifreq; if (ioctl(fd, SIOCGLIFFLAGS, &lifrcopy) < 0) { - avahi_log_error(__FILE__": ioctl(SIOCGLIFFLAGS) %s", strerror(errno)); + catta_log_error(__FILE__": ioctl(SIOCGLIFFLAGS) %s", strerror(errno)); return; } flags = lifrcopy.lifr_flags; if (ioctl(fd, SIOCGLIFMTU, &lifrcopy) < 0) { - avahi_log_error(__FILE__": ioctl(SIOCGLIFMTU) %s", strerror(errno)); + catta_log_error(__FILE__": ioctl(SIOCGLIFMTU) %s", strerror(errno)); return; } mtu = lifrcopy.lifr_metric; if (ioctl(fd, SIOCGLIFADDR, &lifrcopy) < 0) { - avahi_log_error(__FILE__": ioctl(SIOCGLIFADDR) %s", strerror(errno)); + catta_log_error(__FILE__": ioctl(SIOCGLIFADDR) %s", strerror(errno)); return; } - addr.proto = avahi_af_to_proto(lifreq->lifr_addr.ss_family); + addr.proto = catta_af_to_proto(lifreq->lifr_addr.ss_family); if (ioctl(fd, SIOCGLIFNETMASK, &lifrcopy) < 0) { - avahi_log_error(__FILE__": ioctl(SIOCGLIFNETMASK) %s", strerror(errno)); + catta_log_error(__FILE__": ioctl(SIOCGLIFNETMASK) %s", strerror(errno)); return; } switch (lifreq->lifr_addr.ss_family) { @@ -420,8 +420,8 @@ static void if_add_interface(struct lifreq *lifreq, AvahiInterfaceMonitor *m, in } index = if_nametoindex(lifreq->lifr_name); - if (!(hw = avahi_interface_monitor_get_hw_interface(m, (AvahiIfIndex) index))) { - if (!(hw = avahi_hw_interface_new(m, (AvahiIfIndex) index))) + if (!(hw = catta_interface_monitor_get_hw_interface(m, (CattaIfIndex) index))) { + if (!(hw = catta_hw_interface_new(m, (CattaIfIndex) index))) return; /* OOM */ hw->flags_ok = @@ -430,26 +430,26 @@ static void if_add_interface(struct lifreq *lifreq, AvahiInterfaceMonitor *m, in !(flags & IFF_LOOPBACK) && (flags & IFF_MULTICAST) && (m->server->config.allow_point_to_point || !(flags & IFF_POINTOPOINT)); - hw->name = avahi_strdup(lifreq->lifr_name); + hw->name = catta_strdup(lifreq->lifr_name); hw->mtu = mtu; /* TODO get mac address */ } - if (!(iface = avahi_interface_monitor_get_interface(m, (AvahiIfIndex)index, addr.proto))) + if (!(iface = catta_interface_monitor_get_interface(m, (CattaIfIndex)index, addr.proto))) return; - if (!(addriface = avahi_interface_monitor_get_address(m, iface, &addr))) - if (!(addriface = avahi_interface_address_new(m, iface, &addr, prefixlen))) + if (!(addriface = catta_interface_monitor_get_address(m, iface, &addr))) + if (!(addriface = catta_interface_address_new(m, iface, &addr, prefixlen))) return; /* OOM */ addriface->global_scope = 1; - avahi_hw_interface_check_relevant(hw); - avahi_hw_interface_update_rrs(hw, 0); + catta_hw_interface_check_relevant(hw); + catta_hw_interface_update_rrs(hw, 0); } #endif -void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { +void catta_interface_monitor_sync(CattaInterfaceMonitor *m) { #ifndef HAVE_STRUCT_LIFCONF size_t needed; int mib[6]; @@ -467,21 +467,21 @@ void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { mib[5] = 0; /* no flags */ if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { - avahi_log_error("sysctl failed: %s", strerror(errno)); - avahi_log_error("route-sysctl-estimate"); + catta_log_error("sysctl failed: %s", strerror(errno)); + catta_log_error("route-sysctl-estimate"); return; } - if ((buf = avahi_malloc(needed)) == NULL) + if ((buf = catta_malloc(needed)) == NULL) { - avahi_log_error("malloc failed in avahi_interface_monitor_sync"); + catta_log_error("malloc failed in catta_interface_monitor_sync"); return; } if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - avahi_log_warn("sysctl failed: %s", strerror(errno)); + catta_log_warn("sysctl failed: %s", strerror(errno)); if (errno == ENOMEM && count++ < 10) { - avahi_log_warn("Routing table grew, retrying"); + catta_log_warn("Routing table grew, retrying"); sleep(1); - avahi_free(buf); + catta_free(buf); goto retry2; } } @@ -492,9 +492,9 @@ void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { } m->list_complete = 1; - avahi_interface_monitor_check_relevant(m); - avahi_interface_monitor_update_rrs(m, 0); - avahi_log_info("Network interface enumeration completed."); + catta_interface_monitor_check_relevant(m); + catta_interface_monitor_update_rrs(m, 0); + catta_log_info("Network interface enumeration completed."); #elif defined (SIOCGLIFNUM) && defined(HAVE_STRUCT_LIFCONF) /* Solaris 8 and later; Sol 7? */ int sockfd; int ret; @@ -504,25 +504,25 @@ void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { struct lifreq *lifreq; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - avahi_log_error(__FILE__": socket(PFROUTE): %s", strerror(errno)); + catta_log_error(__FILE__": socket(PFROUTE): %s", strerror(errno)); return; } lifc.lifc_buf = NULL; lifn.lifn_family = AF_UNSPEC; lifn.lifn_flags = 0; if (ioctl(sockfd, SIOCGLIFNUM, &lifn) < 0) { - avahi_log_error(__FILE__": ioctl(SIOCGLIFNUM): %s", strerror(errno)); + catta_log_error(__FILE__": ioctl(SIOCGLIFNUM): %s", strerror(errno)); goto end; } lifc.lifc_len = lifn.lifn_count * sizeof (struct lifreq); - if ((lifc.lifc_buf = avahi_malloc(lifc.lifc_len)) == NULL) { - avahi_log_error("malloc failed in avahi_interface_monitor_sync"); + if ((lifc.lifc_buf = catta_malloc(lifc.lifc_len)) == NULL) { + catta_log_error("malloc failed in catta_interface_monitor_sync"); goto end; } lifc.lifc_family = NULL; lifc.lifc_flags = 0; if(ioctl(sockfd, SIOCGLIFCONF, &lifc) < 0) { - avahi_log_error(__FILE__": ioctl(SIOCGLIFCONF): %s", strerror(errno)); + catta_log_error(__FILE__": ioctl(SIOCGLIFCONF): %s", strerror(errno)); goto end; } lifreq = lifc.lifc_req; @@ -532,12 +532,12 @@ void avahi_interface_monitor_sync(AvahiInterfaceMonitor *m) { lifreq++; } m->list_complete = 1; - avahi_interface_monitor_check_relevant(m); - avahi_interface_monitor_update_rrs(m, 0); + catta_interface_monitor_check_relevant(m); + catta_interface_monitor_update_rrs(m, 0); end: close(sockfd); - avahi_free(lifc.lifc_buf); + catta_free(lifc.lifc_buf); - avahi_log_info("Network interface enumeration completed."); + catta_log_info("Network interface enumeration completed."); #endif }