--- embedaddon/dnsmasq/src/netlink.c 2013/07/29 19:37:40 1.1.1.1 +++ embedaddon/dnsmasq/src/netlink.c 2016/11/02 09:57:01 1.1.1.3 @@ -1,4 +1,4 @@ -/* dnsmasq is Copyright (c) 2000-2013 Simon Kelley +/* dnsmasq is Copyright (c) 2000-2016 Simon Kelley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -38,8 +38,7 @@ static struct iovec iov; static u32 netlink_pid; -static int nl_async(struct nlmsghdr *h); -static void nl_newaddress(time_t now); +static void nl_async(struct nlmsghdr *h); void netlink_init(void) { @@ -143,7 +142,7 @@ int iface_enumerate(int family, void *parm, int (*call struct nlmsghdr *h; ssize_t len; static unsigned int seq = 0; - int callback_ok = 1, newaddr = 0; + int callback_ok = 1; struct { struct nlmsghdr nlh; @@ -170,10 +169,10 @@ int iface_enumerate(int family, void *parm, int (*call req.g.rtgen_family = family; /* Don't block in recvfrom if send fails */ - while((len = sendto(daemon->netlinkfd, (void *)&req, sizeof(req), 0, - (struct sockaddr *)&addr, sizeof(addr))) == -1 && retry_send()); - - if (len == -1) + while(retry_send(sendto(daemon->netlinkfd, (void *)&req, sizeof(req), 0, + (struct sockaddr *)&addr, sizeof(addr)))); + + if (errno != 0) return 0; while (1) @@ -192,18 +191,10 @@ int iface_enumerate(int family, void *parm, int (*call if (h->nlmsg_seq != seq || h->nlmsg_pid != netlink_pid || h->nlmsg_type == NLMSG_ERROR) { /* May be multicast arriving async */ - if (nl_async(h)) - newaddr = 1; + nl_async(h); } else if (h->nlmsg_type == NLMSG_DONE) - { - /* handle async new interface address arrivals, these have to be done - after we complete as we're not re-entrant */ - if (newaddr) - nl_newaddress(dnsmasq_time()); - - return callback_ok; - } + return callback_ok; else if (h->nlmsg_type == RTM_NEWADDR && family != AF_UNSPEC && family != AF_LOCAL) { struct ifaddrmsg *ifa = NLMSG_DATA(h); @@ -215,8 +206,10 @@ int iface_enumerate(int family, void *parm, int (*call if (ifa->ifa_family == AF_INET) { struct in_addr netmask, addr, broadcast; - - netmask.s_addr = htonl(0xffffffff << (32 - ifa->ifa_prefixlen)); + char *label = NULL; + + netmask.s_addr = htonl(~(in_addr_t)0 << (32 - ifa->ifa_prefixlen)); + addr.s_addr = 0; broadcast.s_addr = 0; @@ -226,12 +219,14 @@ int iface_enumerate(int family, void *parm, int (*call addr = *((struct in_addr *)(rta+1)); else if (rta->rta_type == IFA_BROADCAST) broadcast = *((struct in_addr *)(rta+1)); + else if (rta->rta_type == IFA_LABEL) + label = RTA_DATA(rta); rta = RTA_NEXT(rta, len1); } if (addr.s_addr && callback_ok) - if (!((*callback)(addr, ifa->ifa_index, netmask, broadcast, parm))) + if (!((*callback)(addr, ifa->ifa_index, label, netmask, broadcast, parm))) callback_ok = 0; } #ifdef HAVE_IPV6 @@ -260,6 +255,9 @@ int iface_enumerate(int family, void *parm, int (*call if (ifa->ifa_flags & IFA_F_DEPRECATED) flags |= IFACE_DEPRECATED; + if (!(ifa->ifa_flags & IFA_F_TEMPORARY)) + flags |= IFACE_PERMANENT; + if (addrp && callback_ok) if (!((*callback)(addrp, (int)(ifa->ifa_prefixlen), (int)(ifa->ifa_scope), (int)(ifa->ifa_index), flags, @@ -290,7 +288,8 @@ int iface_enumerate(int family, void *parm, int (*call rta = RTA_NEXT(rta, len1); } - if (inaddr && mac && callback_ok) + if (!(neigh->ndm_state & (NUD_NOARP | NUD_INCOMPLETE | NUD_FAILED)) && + inaddr && mac && callback_ok) if (!((*callback)(neigh->ndm_family, inaddr, mac, maclen, parm))) callback_ok = 0; } @@ -322,11 +321,11 @@ int iface_enumerate(int family, void *parm, int (*call } } -void netlink_multicast(time_t now) +void netlink_multicast(void) { ssize_t len; struct nlmsghdr *h; - int flags, newaddr = 0; + int flags; /* don't risk blocking reading netlink messages here. */ if ((flags = fcntl(daemon->netlinkfd, F_GETFL)) == -1 || @@ -335,24 +334,19 @@ void netlink_multicast(time_t now) if ((len = netlink_recv()) != -1) for (h = (struct nlmsghdr *)iov.iov_base; NLMSG_OK(h, (size_t)len); h = NLMSG_NEXT(h, len)) - if (nl_async(h)) - newaddr = 1; + nl_async(h); /* restore non-blocking status */ fcntl(daemon->netlinkfd, F_SETFL, flags); - - if (newaddr) - nl_newaddress(now); } -static int nl_async(struct nlmsghdr *h) +static void nl_async(struct nlmsghdr *h) { if (h->nlmsg_type == NLMSG_ERROR) { struct nlmsgerr *err = NLMSG_DATA(h); if (err->error != 0) my_syslog(LOG_ERR, _("netlink returns error: %s"), strerror(-(err->error))); - return 0; } else if (h->nlmsg_pid == 0 && h->nlmsg_type == RTM_NEWROUTE) { @@ -364,54 +358,11 @@ static int nl_async(struct nlmsghdr *h) struct rtmsg *rtm = NLMSG_DATA(h); if (rtm->rtm_type == RTN_UNICAST && rtm->rtm_scope == RT_SCOPE_LINK) - { - /* Force re-reading resolv file right now, for luck. */ - daemon->last_resolv = 0; - - if (daemon->srv_save) - { - int fd; - - if (daemon->srv_save->sfd) - fd = daemon->srv_save->sfd->fd; - else if (daemon->rfd_save && daemon->rfd_save->refcount != 0) - fd = daemon->rfd_save->fd; - else - return 0; - - while(sendto(fd, daemon->packet, daemon->packet_len, 0, - &daemon->srv_save->addr.sa, sa_len(&daemon->srv_save->addr)) == -1 && retry_send()); - } - } - return 0; + queue_event(EVENT_NEWROUTE); } else if (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR) - return 1; /* clever bind mode - rescan */ - - return 0; + queue_event(EVENT_NEWADDR); } - -static void nl_newaddress(time_t now) -{ - if (option_bool(OPT_CLEVERBIND) || daemon->doing_dhcp6 || daemon->doing_ra) - enumerate_interfaces(); - - if (option_bool(OPT_CLEVERBIND)) - create_bound_listeners(0); - -#ifdef HAVE_DHCP6 - if (daemon->doing_dhcp6 || daemon->doing_ra) - { - join_multicast(0); - dhcp_construct_contexts(now); - } - - if (daemon->doing_dhcp6) - lease_find_interfaces(now); -#endif -} - - #endif