| 1879 | } |
| 1880 | |
| 1881 | static struct pfr_ktable * |
| 1882 | pfr_create_ktable(struct pfr_table *tbl, long tzero, int attachruleset) |
| 1883 | { |
| 1884 | struct pfr_ktable *kt; |
| 1885 | struct pf_kruleset *rs; |
| 1886 | int pfr_dir, pfr_op; |
| 1887 | |
| 1888 | PF_RULES_WASSERT(); |
| 1889 | |
| 1890 | kt = malloc(sizeof(*kt), M_PFTABLE, M_NOWAIT|M_ZERO); |
| 1891 | if (kt == NULL) |
| 1892 | return (NULL); |
| 1893 | kt->pfrkt_t = *tbl; |
| 1894 | |
| 1895 | if (attachruleset) { |
| 1896 | rs = pf_find_or_create_kruleset(tbl->pfrt_anchor); |
| 1897 | if (!rs) { |
| 1898 | pfr_destroy_ktable(kt, 0); |
| 1899 | return (NULL); |
| 1900 | } |
| 1901 | kt->pfrkt_rs = rs; |
| 1902 | rs->tables++; |
| 1903 | } |
| 1904 | |
| 1905 | for (pfr_dir = 0; pfr_dir < PFR_DIR_MAX; pfr_dir ++) { |
| 1906 | for (pfr_op = 0; pfr_op < PFR_OP_TABLE_MAX; pfr_op ++) { |
| 1907 | kt->pfrkt_packets[pfr_dir][pfr_op] = |
| 1908 | counter_u64_alloc(M_NOWAIT); |
| 1909 | if (! kt->pfrkt_packets[pfr_dir][pfr_op]) { |
| 1910 | pfr_destroy_ktable(kt, 0); |
| 1911 | return (NULL); |
| 1912 | } |
| 1913 | kt->pfrkt_bytes[pfr_dir][pfr_op] = |
| 1914 | counter_u64_alloc(M_NOWAIT); |
| 1915 | if (! kt->pfrkt_bytes[pfr_dir][pfr_op]) { |
| 1916 | pfr_destroy_ktable(kt, 0); |
| 1917 | return (NULL); |
| 1918 | } |
| 1919 | } |
| 1920 | } |
| 1921 | kt->pfrkt_match = counter_u64_alloc(M_NOWAIT); |
| 1922 | if (! kt->pfrkt_match) { |
| 1923 | pfr_destroy_ktable(kt, 0); |
| 1924 | return (NULL); |
| 1925 | } |
| 1926 | |
| 1927 | kt->pfrkt_nomatch = counter_u64_alloc(M_NOWAIT); |
| 1928 | if (! kt->pfrkt_nomatch) { |
| 1929 | pfr_destroy_ktable(kt, 0); |
| 1930 | return (NULL); |
| 1931 | } |
| 1932 | |
| 1933 | if (!rn_inithead((void **)&kt->pfrkt_ip4, |
| 1934 | offsetof(struct sockaddr_in, sin_addr) * 8) || |
| 1935 | !rn_inithead((void **)&kt->pfrkt_ip6, |
| 1936 | offsetof(struct sockaddr_in6, sin6_addr) * 8)) { |
| 1937 | pfr_destroy_ktable(kt, 0); |
| 1938 | return (NULL); |
no test coverage detected