Changeset 989 for vendor/current/source3/nmbd
- Timestamp:
- Nov 25, 2016, 8:04:54 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/nmbd/nmbd_packets.c
r988 r989 1684 1684 enum packet_type type; 1685 1685 bool broadcast; 1686 int fd; 1687 bool triggered; 1686 1688 }; 1687 1689 1688 static bool create_listen_pollfds(struct pollfd **pfds, 1689 struct socket_attributes **pattrs, 1690 static bool create_listen_array(struct socket_attributes **pattrs, 1690 1691 int *pnum_sockets) 1691 1692 { … … 1693 1694 int count = 0; 1694 1695 int num = 0; 1695 struct pollfd *fds;1696 1696 struct socket_attributes *attrs; 1697 1697 … … 1717 1717 } 1718 1718 1719 fds = talloc_zero_array(NULL, struct pollfd, count);1720 if ( fds == NULL) {1721 DEBUG(1, (" create_listen_pollfds: malloc fail for fds. "1719 attrs = talloc_zero_array(NULL, struct socket_attributes, count); 1720 if (attrs == NULL) { 1721 DEBUG(1, ("talloc fail for attrs. " 1722 1722 "size %d\n", count)); 1723 1723 return true; 1724 1724 } 1725 1725 1726 attrs = talloc_array(NULL, struct socket_attributes, count);1727 if (fds == NULL) {1728 DEBUG(1, ("create_listen_pollfds: malloc fail for attrs. "1729 "size %d\n", count));1730 TALLOC_FREE(fds);1731 return true;1732 }1733 1734 1726 num = 0; 1735 1727 1736 fds[num].fd = ClientNMB;1728 attrs[num].fd = ClientNMB; 1737 1729 attrs[num].type = NMB_PACKET; 1738 1730 attrs[num].broadcast = false; 1739 1731 num += 1; 1740 1732 1741 fds[num].fd = ClientDGRAM;1733 attrs[num].fd = ClientDGRAM; 1742 1734 attrs[num].type = DGRAM_PACKET; 1743 1735 attrs[num].broadcast = false; … … 1747 1739 1748 1740 if (subrec->nmb_sock != -1) { 1749 fds[num].fd = subrec->nmb_sock;1741 attrs[num].fd = subrec->nmb_sock; 1750 1742 attrs[num].type = NMB_PACKET; 1751 1743 attrs[num].broadcast = false; … … 1754 1746 1755 1747 if (subrec->nmb_bcast != -1) { 1756 fds[num].fd = subrec->nmb_bcast;1748 attrs[num].fd = subrec->nmb_bcast; 1757 1749 attrs[num].type = NMB_PACKET; 1758 1750 attrs[num].broadcast = true; … … 1761 1753 1762 1754 if (subrec->dgram_sock != -1) { 1763 fds[num].fd = subrec->dgram_sock;1755 attrs[num].fd = subrec->dgram_sock; 1764 1756 attrs[num].type = DGRAM_PACKET; 1765 1757 attrs[num].broadcast = false; … … 1768 1760 1769 1761 if (subrec->dgram_bcast != -1) { 1770 fds[num].fd = subrec->dgram_bcast;1762 attrs[num].fd = subrec->dgram_bcast; 1771 1763 attrs[num].type = DGRAM_PACKET; 1772 1764 attrs[num].broadcast = true; … … 1774 1766 } 1775 1767 } 1776 1777 TALLOC_FREE(*pfds);1778 *pfds = fds;1779 1768 1780 1769 TALLOC_FREE(*pattrs); … … 1865 1854 1866 1855 /**************************************************************************** 1856 Timeout callback - just notice we timed out. 1857 ***************************************************************************/ 1858 1859 static void nmbd_timeout_handler(struct tevent_context *ev, 1860 struct tevent_timer *te, 1861 struct timeval current_time, 1862 void *private_data) 1863 { 1864 bool *got_timeout = private_data; 1865 *got_timeout = true; 1866 } 1867 1868 /**************************************************************************** 1869 fd callback - remember the fd that triggered. 1870 ***************************************************************************/ 1871 1872 static void nmbd_fd_handler(struct tevent_context *ev, 1873 struct tevent_fd *fde, 1874 uint16_t flags, 1875 void *private_data) 1876 { 1877 struct socket_attributes *attr = private_data; 1878 attr->triggered = true; 1879 } 1880 1881 /**************************************************************************** 1867 1882 Listens for NMB or DGRAM packets, and queues them. 1868 1883 return True if the socket is dead … … 1871 1886 bool listen_for_packets(struct messaging_context *msg, bool run_election) 1872 1887 { 1873 static struct pollfd *fds = NULL;1874 1888 static struct socket_attributes *attrs = NULL; 1875 1889 static int listen_number = 0; 1876 1890 int num_sockets; 1877 1891 int i; 1878 1879 int pollrtn;1880 int timeout; 1892 int loop_rtn; 1893 int timeout_secs; 1894 1881 1895 #ifndef SYNC_DNS 1882 1896 int dns_fd; … … 1884 1898 #endif 1885 1899 struct processed_packet *processed_packet_list = NULL; 1886 1887 if ((fds == NULL) || rescan_listen_set) { 1888 if (create_listen_pollfds(&fds, &attrs, &listen_number)) { 1900 struct tevent_timer *te = NULL; 1901 bool got_timeout = false; 1902 TALLOC_CTX *frame = talloc_stackframe(); 1903 1904 if ((attrs == NULL) || rescan_listen_set) { 1905 if (create_listen_array(&attrs, &listen_number)) { 1889 1906 DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); 1907 TALLOC_FREE(frame); 1890 1908 return True; 1891 1909 } … … 1893 1911 } 1894 1912 1895 /*1896 * "fds" can be enlarged by event_add_to_poll_args1897 * below. Shrink it again to what was given to us by1898 * create_listen_pollfds.1899 */1900 1901 fds = talloc_realloc(NULL, fds, struct pollfd, listen_number);1902 if (fds == NULL) {1903 return true;1904 }1905 1913 num_sockets = listen_number; 1906 1914 … … 1908 1916 dns_fd = asyncdns_fd(); 1909 1917 if (dns_fd != -1) { 1910 fds = talloc_realloc(NULL, fds, struct pollfd, num_sockets+1); 1911 if (fds == NULL) { 1918 attrs = talloc_realloc(NULL, 1919 attrs, 1920 struct socket_attributes, 1921 num_sockets + 1); 1922 if (attrs == NULL) { 1923 TALLOC_FREE(frame); 1912 1924 return true; 1913 1925 } 1914 1926 dns_pollidx = num_sockets; 1915 fds[num_sockets].fd = dns_fd; 1927 attrs[dns_pollidx].fd = dns_fd; 1928 /* 1929 * dummy values, we only need 1930 * fd and triggered. 1931 */ 1932 attrs[dns_pollidx].type = NMB_PACKET; 1933 attrs[dns_pollidx].broadcast = false; 1916 1934 num_sockets += 1; 1917 1935 } … … 1919 1937 1920 1938 for (i=0; i<num_sockets; i++) { 1921 fds[i].events = POLLIN|POLLHUP; 1922 } 1923 1924 /* Process a signal and timer events now... */ 1925 if (run_events_poll(nmbd_event_context(), 0, NULL, 0)) { 1926 return False; 1939 struct tevent_fd *tfd = tevent_add_fd(nmbd_event_context(), 1940 frame, 1941 attrs[i].fd, 1942 TEVENT_FD_READ, 1943 nmbd_fd_handler, 1944 &attrs[i]); 1945 if (tfd == NULL) { 1946 TALLOC_FREE(frame); 1947 return true; 1948 } 1949 attrs[i].triggered = false; 1927 1950 } 1928 1951 … … 1934 1957 */ 1935 1958 1936 timeout = ((run_election||num_response_packets) 1937 ? 1 : NMBD_SELECT_LOOP) * 1000; 1938 1939 event_add_to_poll_args(nmbd_event_context(), NULL, 1940 &fds, &num_sockets, &timeout); 1941 1942 pollrtn = poll(fds, num_sockets, timeout); 1943 1944 if (run_events_poll(nmbd_event_context(), pollrtn, fds, num_sockets)) { 1945 return False; 1946 } 1947 1948 if (pollrtn == -1) { 1949 return False; 1959 if (run_election||num_response_packets) { 1960 timeout_secs = 1; 1961 } else { 1962 timeout_secs = NMBD_SELECT_LOOP; 1963 } 1964 1965 te = tevent_add_timer(nmbd_event_context(), 1966 frame, 1967 tevent_timeval_current_ofs(timeout_secs, 0), 1968 nmbd_timeout_handler, 1969 &got_timeout); 1970 if (te == NULL) { 1971 TALLOC_FREE(frame); 1972 return true; 1973 } 1974 1975 loop_rtn = tevent_loop_once(nmbd_event_context()); 1976 1977 if (loop_rtn == -1) { 1978 TALLOC_FREE(frame); 1979 return true; 1980 } 1981 1982 if (got_timeout) { 1983 TALLOC_FREE(frame); 1984 return false; 1950 1985 } 1951 1986 1952 1987 #ifndef SYNC_DNS 1953 1988 if ((dns_fd != -1) && (dns_pollidx != -1) && 1954 (fds[dns_pollidx].revents & (POLLIN|POLLHUP|POLLERR))){1989 attrs[dns_pollidx].triggered){ 1955 1990 run_dns_queue(msg); 1991 TALLOC_FREE(frame); 1992 return false; 1956 1993 } 1957 1994 #endif … … 1964 2001 int client_port; 1965 2002 1966 if ( (fds[i].revents & (POLLIN|POLLHUP|POLLERR)) == 0) {2003 if (!attrs[i].triggered) { 1967 2004 continue; 1968 2005 } … … 1982 2019 } 1983 2020 1984 packet = read_packet( fds[i].fd, packet_type);2021 packet = read_packet(attrs[i].fd, packet_type); 1985 2022 if (!packet) { 1986 2023 continue; … … 1992 2029 */ 1993 2030 if (lp_bind_interfaces_only() && 1994 ( fds[i].fd == client_fd) &&2031 (attrs[i].fd == client_fd) && 1995 2032 (!is_local_net_v4(packet->ip))) { 1996 2033 DEBUG(7,("discarding %s packet sent to broadcast socket from %s:%d\n", … … 2031 2068 if (attrs[i].broadcast) { 2032 2069 /* this is a broadcast socket */ 2033 packet->send_fd = fds[i-1].fd;2070 packet->send_fd = attrs[i-1].fd; 2034 2071 } else { 2035 2072 /* this is already a unicast socket */ 2036 packet->send_fd = fds[i].fd;2073 packet->send_fd = attrs[i].fd; 2037 2074 } 2038 2075 … … 2041 2078 2042 2079 free_processed_packet_list(&processed_packet_list); 2080 TALLOC_FREE(frame); 2043 2081 return False; 2044 2082 }
Note:
See TracChangeset
for help on using the changeset viewer.