* Delete one or multiple bw_meter entries */
| 1851 | * Delete one or multiple bw_meter entries |
| 1852 | */ |
| 1853 | static int |
| 1854 | del_bw_upcall(struct bw_upcall *req) |
| 1855 | { |
| 1856 | struct mfc *mfc; |
| 1857 | struct bw_meter *x; |
| 1858 | |
| 1859 | if (!(V_mrt_api_config & MRT_MFC_BW_UPCALL)) |
| 1860 | return EOPNOTSUPP; |
| 1861 | |
| 1862 | MFC_LOCK(); |
| 1863 | |
| 1864 | /* Find the corresponding MFC entry */ |
| 1865 | mfc = mfc_find(&req->bu_src, &req->bu_dst); |
| 1866 | if (mfc == NULL) { |
| 1867 | MFC_UNLOCK(); |
| 1868 | return EADDRNOTAVAIL; |
| 1869 | } else if (req->bu_flags & BW_UPCALL_DELETE_ALL) { |
| 1870 | /* |
| 1871 | * Delete all bw_meter entries for this mfc |
| 1872 | */ |
| 1873 | struct bw_meter *list; |
| 1874 | |
| 1875 | list = mfc->mfc_bw_meter; |
| 1876 | mfc->mfc_bw_meter = NULL; |
| 1877 | free_bw_list(list); |
| 1878 | MFC_UNLOCK(); |
| 1879 | return 0; |
| 1880 | } else { /* Delete a single bw_meter entry */ |
| 1881 | struct bw_meter *prev; |
| 1882 | uint32_t flags = 0; |
| 1883 | |
| 1884 | flags = compute_bw_meter_flags(req); |
| 1885 | |
| 1886 | /* Find the bw_meter entry to delete */ |
| 1887 | for (prev = NULL, x = mfc->mfc_bw_meter; x != NULL; |
| 1888 | prev = x, x = x->bm_mfc_next) { |
| 1889 | if ((BW_TIMEVALCMP(&x->bm_threshold.b_time, |
| 1890 | &req->bu_threshold.b_time, ==)) && |
| 1891 | (x->bm_threshold.b_packets == req->bu_threshold.b_packets) && |
| 1892 | (x->bm_threshold.b_bytes == req->bu_threshold.b_bytes) && |
| 1893 | (x->bm_flags & BW_METER_USER_FLAGS) == flags) |
| 1894 | break; |
| 1895 | } |
| 1896 | if (x != NULL) { /* Delete entry from the list for this MFC */ |
| 1897 | if (prev != NULL) |
| 1898 | prev->bm_mfc_next = x->bm_mfc_next; /* remove from middle*/ |
| 1899 | else |
| 1900 | x->bm_mfc->mfc_bw_meter = x->bm_mfc_next;/* new head of list */ |
| 1901 | |
| 1902 | unschedule_bw_meter(x); |
| 1903 | MFC_UNLOCK(); |
| 1904 | /* Free the bw_meter entry */ |
| 1905 | free(x, M_BWMETER); |
| 1906 | return 0; |
| 1907 | } else { |
| 1908 | MFC_UNLOCK(); |
| 1909 | return EINVAL; |
| 1910 | } |
no test coverage detected